To Get the Runtime Context and set the value of the document number

This code sample will get the run time context and checks if the context is ‘WEBSERVICES’

then fetches the field value of the source and compares if this is equal to ‘web Services’

if the source condition is satisfied then the system fetches the Document number and then suffix it will -WC

 const afterSubmit = (scriptContext) => {

      try {

        if (scriptContext.type === scriptContext.UserEventType.CREATE) {

          if (runtime.executionContext === “WEBSERVICES”) {

            let salesOrderRecordObj = scriptContext.newRecord;

            log.debug(‘inside the context’);

            setSoDocumentNoFromWooCommerce(salesOrderRecordObj);

          }

        }

      } catch (error) {

        log.error(‘error @afterSubmit’, error);

      }

    }

function setSoDocumentNoFromWooCommerce(salesOrderRecordObj) {

      try {

        let sourceFieldValue = salesOrderRecordObj.getValue({ fieldId: ‘source’ });

        log.debug(‘sourceFieldValue’, sourceFieldValue);

        if (sourceFieldValue === “Web Services”) {

          let wooCommerceOrderNumber = salesOrderRecordObj.getValue({ fieldId: ‘tranid’ });

          log.debug(‘wooCommerceOrderNumber’, wooCommerceOrderNumber);

          if (wooCommerceOrderNumber) {

            let soDocNumber = wooCommerceOrderNumber + ‘-WC’;

            salesOrderRecordObj.setValue({

              fieldId: ‘tranid’,

              value: soDocNumber

            });

          }

        }

      } catch (error) {

        log.error(‘error @setSoDocumentNoFromWooCommerce’, error);

      }

    }

Leave a comment

Your email address will not be published. Required fields are marked *