0

I hope you are well. I have my user event script to create custom button on netsuite message record. I have client script to refresh the page on button click. I am able to get selected template value in client script before and after refreshing the page but not able to set selected template on custom field (or any field) of message record.I So I want to pass selected template Id from client script to user event script and set in user event before load.

Thanks in advance!

//User Event BeforeLoad
 function beforeLoad(scriptContext) {
        try {
            if (scriptContext.type === 'create') {
                var form = scriptContext.form;
                var field = form.addField({
                    id : 'custpage_abc_text',
                    type : serverWidget.FieldType.TEXT,
                    label : 'Custom Template Id'
                });
                form.addButton({
                    id: 'custpage_email_message_button',
                    label: 'Refresh',
                    functionName: 'clientButtonClick'
                });
                form.clientScriptModulePath = 'SuiteScripts/cs_get_template.js';
                form.addButton({
                    id: 'custpage_email_message_button',
                    label: 'Refresh',
                    functionName: 'clientButtonClick'
                });

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

                if(templateId == 272)
                {
                    //Set few sublists
            }
           
            }
        } catch (e) {
            log.error({ title: 'Error Details', details: e });
        }
    }

//Client Script
  function clientButtonClick() {
        try {
            var currentRec = currentRecord.get();
            var templateId = currentRec.getValue({fieldId:"template"})
            alert("templateId before refresh"+templateId);
            window.onbeforeunload = null;
            window.location.href = window.location.href;
            var templateId = currentRec.getValue({fieldId:"template"})
            alert("templateId after refresh"+templateId);
           } catch (e) {
          log.error("error in clientButtonClick()",e);
        }

    }

function pageInit() {
    // Initialization code
}

1 Answer 1

0
function afterSubmit(context) {
        try {
            if (context.type !== 'create' && context.type !== 'edit') return;

            var newRecord = context.newRecord;
            var salesOrderId = newRecord.id;
            var orderInfoId = newRecord.getValue('custpage_order_info');

            if (orderInfoId) {
                // Use submitFields instead of record.load for better performance and avoiding permission issues
                record.submitFields({
                    type: 'customrecord_order_info', // Order Info record type
                    id: orderInfoId,
                    values: {
                        custrecord__related_sales_order: salesOrderId
                    }
                });

                log.debug("afterSubmit Executed", "Updated Related Sales Order for Order Info ID: " + orderInfoId);
            } else {
                log.debug("afterSubmit Executed", "No Order Info ID found, skipping update.");
            }
        } catch (e) {
            log.error("Error in afterSubmit", e.message);
        }
    }

by these approach

you set the value in custom field

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.