Reloading a sublist in SuiteScript 2.0 - netsuite

I'm hoping someone can help. I recently wrote a SuiteScript 2.0 project. The primary suitelet displays transaction/customer info in a sublist that has a SublistType of LIST. Right now we're displaying 750 records in the list at a time, but there can potentially be hundreds or even thousands of additional records, so the users want to have a Next and Previous button that will allow them to cycle to the next page of results.
The problem is that I cannot seem to update that sublist for the life of me. The fields on the sublist are all text fields except for one checkbox. Inside of a CLIENT SCRIPT, I've been trying things similar to the code below. (I removed all but one of the setCurrentSublistValue calls to shorten the code):
var currentRec = currentRecord.get();
currentRec.selectLine({
sublistId: 'custpage_studstatement',
line: 0
});
currentRec.setCurrentSublistValue({
sublistId: 'custpage_studstatement',
fieldId: 'custpage_show',
value: false
});
currentRec.commitLine({sublistId: 'custpage_studstatement'});
It will spin through all of the sublist items, but ONLY the checkbox gets updated. None of the text fields change, and no exceptions are thrown.
If I change the sublist to type EDITOR, I can update all of the fields on the line without a problem. It basically behaves they way I want it to. Also, if I change the FieldDisplayType on any of the text fields, I can then update those individual fields, but neither of those options are acceptable. We don't want the users to be able to edit those fields/lines like that. The LIST sublist is the one we want, but I'm beginning to think you cannot update LIST sublists from a client script, even though the docs suggest that you can. (although it's not definitive. The docs are a bit sketchy)
So I guess I'm mostly just looking for a high level answer, because I'm not sure I'm even approaching this correctly. If you have a custom sublist that is just a LIST, how would you add the ability to page through to the next set of results? Should updating that sublist be done in the client script? If so, how? Or should it be in the suitelet? And if so, how? (I've tried some various things in the suitelet as well, but I'll omit that to keep this from getting any longer) Thanks in advance

I am making a few assumptions here:
Your suitelet creates a custom page - it has a sublist. The sublist is a form.sublist. and inside it are fields, sublist.addfields.
What you can do is use sublist.setSublistValue and it can populate the whole sublist.
Now, It depends on how you obtain the values of your sublist - you can have additional fields in the body - the bodys will define a filter that filters this search. This will scale down results shown in the page a lot to achieve the result you have.
You can indeed have next and previous page - of which you have your search object, and your next page/previous page button will impact your results.getRange() function - instead of for example getRange({start:0 end:1000}) to be getRange({start:1000 end:2000}) greater and beyond that. (This isn't the only way, but how I imagine I would do it)
Either way, how you get your dataset - a search.create will be in your suitelet, the getRange will be in your suitelet. How you setSublistValue will be in your suitelet. How you create your buttons will be in the suitelet.
But, the function that the button triggers will be in your client script, loaded via form.clientScriptModulePath = './xxx.js'; Something like that. This client script can trigger scripts via url.resolveScript, and trigger the suitelet to add params. Passing some parameter to indicate which 'page' to load (first set of results..second set.. etc.)
Hope this will point you in the right direction!

You can not update the sublist in suitelet using Client Script and with sublist being LIST type.
You can create Next and Previous button and on click of these button you can again hit the suitelet url from ClientScript and passing the pagenumber parameter and displaying the sublist dataset in forward and backward direction depending upon the value of pagenumber.
For eg:- if you are displaying 750 pages at one time then the first time you press Next your pagenumber parameter will be 2 and you will show next 750 entries in the page.

Related

SuiteScript 2.0 way to refresh a sublist in a client script

I had an old SuiteScript 1.0 script that added any number of rows to a sublist of an Item Fulfillment when a button was pushed. In that script when i was done I was able to call
nlapiRefreshLineItems('recmachcustrecord_contents_sublist');
What that did was refreshed the subtab contents so it would show the up to date list with the new rows added (or removed).
Anyhow it seems that call does not have a 2.0 equivalent. I noticed I could go and refresh the whole page with the browser RELOAD and it would of course show correctly. Any suggestions on any ways to facilitate that updated sublist via scripting?
via script you have to write a function and trigger it yourself.
You can get the field at pageInit using context.currentRecord.getField and then use the same to setSelectOption

NetSuite sublist

I am having a problem finding out an id of a sublist. I am using SuiteScript 1.0. For instance, I need to list the components of an assembly item record, how do I find out the list id and the "type and field name to use in the nlapiGetCurrentLineItemValue or nlapiGetCurrentLineItemValue methods. What I am looking for is how now and in the future when presented with a sublist, do I go about finding the ids of the objects needed. I have internal ids turned on but that does not help in the sublist view. What is the best way to get this information when I need it? thanks for any help you may give.
You can use nlapiGetAllLineItems() to get an array of all the sublists. You may need to load the record first and do record.getAllLineItems()
I have found the most useful method for figuring out internalids is to run nlapiLoadRecord(..) in your Browser Console and examine the resulting object. Another trick is the add &xml=T to the end of the URL of the record, which displays the record in XML format. NetSuite also documents most of the internalids in the Records Browser.
In this case you use console in Google Chrome. Open the Specific Assembly Item Record page and Press F12 and select console.After give following code
nlapiLoadRecord('assemblyitem', 90088(id for specific record));
after show result in console. Select linefields and Item. Now it show the fields of sublist. If You have any doubt let me know.

NetSuite : nlapiRemoveLineItem() issue if no value is selected in the list

so we are facing this weird issue. There is a Customer list on the form which is of the type List/Record. On the basis of Customer selected in this list, I clear the transaction list on the child form using nlapiRemoveLineItem() call . Everything works well TILL the customer is selected properly in the customer list.
Now, lets say I just type customer name abc & it gets autopopulated without selecting it as such, in this case, the nlapiRemoveLineItem() on the other list fails miserably and simply adds new items in this list.
What is really happening here ? Can anyone help ?
Javascript runs asynchronously, which means if you call an event like loading the customer, the browser won't wait for the result to come back before it executes the next command, in this case the nlapiRemoveLineItem.
So the sequence of events that is happening goes:
Set the customer
Remove line items
Customer is loaded
Line items from customer are populated
And what you want is:
Set the customer
Customer is loaded
Line items from customer are populated
Remove line items
To achieve this you could either use a promise library like q (best way), make a while loop to wait for the customer to come back, or do it the lazy way and do a setTimeout and execute the line removal around the time you expect the customer to come back.

update netsuite parent field via suitescript in view mode

I have scripts that react off of, for example, a client Recalc client event. For example, on my form I have a subtab that users may add or remove items from. Based on actions on this subtab (housing a child record of the parent) I would like a field on the parent to update (say to show a total from the children records).
As I was saying, these events seem to work fine if in edit mode but they do not work correctly in view mode. (even in view mode these child records have a "Delete" option at the end of each row in the subtab. This was provided by netsuite by default.
I wondered if anyone had any tips to best allow this parent field to update real time while in updating the subtab rows with the form in view mode.
Thanks.
You can make a custom field on the parent (header) whose value is determined by saved search. For instance, make a saved search that totals the line values by transaction. Be sure to make it filter by transaction in the Available Filters tab. Make the search public so everyone can use it.
Create the custom field that sources the total from the saved search. Make sure to uncheck the "Store Value" checkbox, as you don't want to store the data, you want to reference the search results. You do this on the Validation and Defaulting tab. You'll see a field for Saved Search there. Choose the search you created above.
As you remove/add/change lines on the transaction, the field updates accordingly. In essence, you don't need a single line of code to make this work - it's all in how you create the search and the custom field that references it.
I have a similar situation posted here.
The NetSuite team answered me by email, and it happens you can't really achieve this on the view mode: some API methods are not available. Their suggestion to my case (and I think it applies to yours too) was really to force a refresh on the whole page.
Of course, you can always achieve this accessing the DOM elements directly, but this isn't a best practice, as your code can stop working if these elements change on a version update.
I had the same problem, I'm not able to restrict on view or remove edit button. But, there was one alternative solution with workflows, you can deploy workflow on child record edit mode restrictions, then if the user clicks edit on view then the record will not be available to edit. This concern will apply to custom record as well.

How to paginate a growing list?

What's a good way to paginate a list that is constantly growing?
For example, a user may open page 2 of some listing, keep looking at it for a while and then open page 3. Meanwhile, new records have been added to the beginning of the list (page 1) and caused page 3 to contain items that could have been on page 2 previously.
Should such a list be paginated from the other end? Then how to deal with the front page and the fact that it would, without special attention, contain TOTAL NUMBER OF ITEMS % PAGE SIZE items (ie. not constant)?
Assuming you have a fixed page size, some specified ordering, and the user is specifying the page they wish to view, I would simply fetch the data accordingly. Trying to do anything more complicated than that will just end up causing you unnecessary headache and confuse the user.
I think the element you're missing here is the ordering. If you specify an ordering then the user will intuitively understand. Also, that's how the majority of pagination is done, so you're not deviating from what you're user really expects.
I'd add a warning to advise the user that new items have come in and allow them to refresh the list. If they choose not to then maintain list in the state it was in when they clicked on the "Page 2" button. You can use a timestamp on the URL to determine which version of the list to serve to which user.
I do not think it's a good idea to page through a growing list. You'd better recalculate items that should be displayed on a page everytime user performs an action.

Resources