Search code examples
suitescriptsuitescript2.0

How to setValue of a field by prompt() through adhoc CS in Netsuite?


I created a Button through UE script in Purchase Order. On hitting an alert/prompt would let the user write the text and on hitting OK in prompt box , that text would be saved in a custombody field. I tried to do submitFields but it doesn't do anything. Can anyone help me with this?

User event code:

        context.form.addButton({
            id: 'custpage_reject',
            label: 'Reject With Reason',
            functionName: 'rejectButton()'
        })
        context.form.clientScriptModulePath = 'SuiteScripts/mx_rejectionReason_cs.js';

Client script function:

function rejectButton() {
    rejectReasonValue = window.prompt("Reason for Rejection ?");
    console.log('prompt:', rejectReasonValue)

    nsCurrentRecord.submitFields({
        type: recType,
        id: recId,
        values: {
          custbody_reasonof_rejection: rejectReasonValue,
        },
        options: {
          enableSourcing: true,
          ignoreMandatoryFields: true
        }
      });
}

Solution


  • Hi

    I think your submitFields wouldn't work on the currently loaded record.

    Try setting the field value on the current record like so:

    currentRecord.setValue('custbody_reasonof_rejection', rejectReasonValue);
    

    Hope this works for you!