Client Script Help – passing data and setting field values

Ok, I am working on a task that seemed easy, and I’ve learned a lot about SS2.x in the process, but just ultimately keep running into limitations, like not being able to source a sublist field from a multi-select, not being able to set field values
in beforeLoad of a User Event script, etc. And I just need some insight on how to continue, or maybe I just start over with a different Script Type and new approach.

Here’s the scenario:

(1) I need to check all items on a Sales Order for data from a custom item field that is a multi-select. Since it is a multi-select, I can’t source a sublist field with the data from the item’s custom multi-select.

(2) Since I can’t source from a multi-select, what I am doing is allowing the user to save the Sales Order so that I can get an orderId (context.newRecord.id), and use that orderId in a (N/search) saved search.

(3) In beforeSubmit of a User Event Script, I set the value of a ‘order is ready’ checkbox from a previous customization to false: order is not ready because I need to process the saved search results.

(4) And then in the subsequent beforeLoad, I run my saved search since I now have an orderId (context.newRecord.id) from allowing the order to save, but setting it ‘not ready.’

(5) Next, I run basic code on the saved search results. If everything is good, I want to set that ‘ready’ checkbox to true: order is ready. Else, I am displaying a warning via a Client Script, where I am passing data from the saved search in the User Event script to the Client Script, and leaving the checkbox false (order not ready)

The warning message works, and all of this works except setting that checkbox to true.

I’ve tried setting it in the beforeLoad, but there is a NetSuite limitation not allowing it:
https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=section_4407991781.html

I’ve tried setting it in the showMessage() function in the Client Script, but the currentRecord there is ready only.

I’ve tried setting it in the pageInit function in the Client Script, and the currentRecord.setValue() call works there and will properly set field values, but in order to know *when* to set that value, I have to pass data into the pageInit function from beforeLoad, and when that happens, it replaces currentRecord with said data, so, currentRecord is now undefined..
I’m calling the Client Script pageInit from the User Event beforeLoad with something like this:


var myObj = {name: 'name', data: 'data'};

var line = context.form.addField({

id: 'custpage_initPage',

label: 'not shown',

type: serverWidget.FieldType.INLINEHTML

});

line.defaultValue = "<script>NS.jQuery(function($){ require(['/SuiteScripts/PathToClientScript/ClientScript'], function(a){ a.pageInit(" +JSON.stringify(myObj)+");});});</script>";


This successfully passes the data into pageInit, but as I mentioned above, it replaces the currentRecord, which is not at all desirable. My next steps are to begin looking at the other Client Script entry points, but thought I’d throw this up here, too.

Any insights/help is appreciated!

Rookie Asked on September 17, 2019 in SuiteScript.

You sound like you have a lot of logic trying to manipulate a ready checkbox. Im not really sure why all your logic isn’t simply in the beforeSubmit entry point. From your description, its because you needed the order internal id for something, but you don’t need the order internal id to get the value of a multi select field. You would need the item internal id for that, and that is available beforeSubmit.

on September 17, 2019.

It sounds like a client script saveRecord function would be fine if you’re not processing may item lines.
You need to loop through the lines gathering the item id’s, perform a search to ascertain the item custom field values and then apply logic on the result to display /not display a message / set your checkbox (if it’s even needed).
You could return false if you do not want the record to be saved until everything is correct. 

on September 18, 2019.

@battk search.lookupFields is what I needed to get grab the data w/o an orderId. Thank you for the help! That allowed me to move almost everything to beforeSubmit, where it worked with the previous customizations. Appreciate it!

on September 18, 2019.
Add Comment
1 Answer(s)

Just in case anyone else sees this. Being new to SS I didn’t really know much about search.lookupFields, but using that allowed me to get the multi-select field values without saving the order and having an orderId, which is what I’d needed in the “normal” saved search. That allowed me to move about 90% of what I was doing out of the beforeLoad into the beforeSubmit, where setting field values is allowed. Might be worth noting that calling a warning message from beforeSubmit is restricted. It seems whether you do it via Client Script or with the 2018.2 addPageInitMessage, it is only available in beforeLoad, which makes sense. Anyway, this is working now and working with the previous customization.

Rookie Answered on September 18, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.