RE: Adding a specific item to any new Sales Order before saved

Hello,

I am trying to create and deploy a SuiteScript but nothing is happening.

 

With the script below I want to automatically add an item to any new Sales Order before the SO is saved.

 

I have the Script Type set to User Event, I have the Before Submit Function checked, and under the Deployment record I have it apply to Sales Order in Testing with an Event Type as Submit

 

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define([‘N/record’],
function (record) {
     function beforeSubmit(context) {
          if (context.type === context.UserEventType.CREATE) {
               var salesOrder = context.newRecord;
               salesOrder.selectNewLine({
                    sublistId:’item’
               });
               salesOrder.setCurrentSublistValue({
                    sublistId:’item’,
                    fieldId:’item’,
                    value: 2231
               });
              salesOrder.setCurrentSublistValue({
                    sublistId:’item’,
                    fieldId:’quantity’,
                    value:1
               });
               salesOrder.commitLine({sublistId:’item’});
          }
     }
return {
beforeSubmit:beforeSubmit
};
});

alexanderm Rookie Asked on April 8, 2023 in How To's.
Add Comment
2 Answers

Hi,

Event Type as Submit and context.type === context.UserEventType.CREATE are different.

I would suggest removing the event type from the script deployment as a first step to check if it works.

Thanks,

Chris

Advanced Answered on April 12, 2023.
Add Comment

Your Answer

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