clientnetsuitemessagesuitescript2.0user-event

Can we retain selected value after reloading the page user event beforeload?


I hope you are well. I'm working on a record creation. I select the value from dropdown field. After that reload the record, I need to:

Retain the selected value from the dropdown. Repopulate the dropdown with the retained value. Use the retained value in a conditional statement to populate another field on the form. The issue is that the dropdown resets to its default state(empty) after the page reload, and I'm unable to access the previously selected value.

 if (scriptContext.type === 'create') {
                var form = scriptContext.form;
                                          
                form.clientScriptModulePath = 'SuiteScripts/cs_get_template.js';
                form.addButton({
                    id: 'custpage_email_message_button',
                    label: 'Refresh',
                    functionName: 'clientButtonClick'
                });

                var selectedTemp = rec.getValue({
                    fieldId: 'template',
                });
                log.debug("selectedTemp",selectedTemp);

                if(templateId == 123)
                {
                    //Code to set some values
            }
           
            }

I am calling client script to reload the page

 function clientButtonClick() {
            var currentRec = currentRecord.get();
            var recordId = currentRec.id;
            var recordType = currentRec.type;
                           
            // Reload the current record
           

            var templateId = currentRec.getValue({fieldId:"template"})

            window.onbeforeunload = null;
            window.location.href = window.location.href;// reload the record 
        }

Solution

  • When you open or redirect to a new record form in NetSuite, you can use URL parameters to pre-populate certain fields.

    If you want the page to load with the template field already set to 123, then you can add template=123 as a URL parameter.