User Event script for the creating custom records for the recurring order

  • ‘customrecord_jj_reorder_chekout_items’ is the record type that the custom record created.
  • ‘custbody_jj_reorder_start_date’, ‘custbody_jj_reorder_end_date’ are the start and end dates of recurring orders.
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(["N/record", "N/search", 'N/https', 'N/format'], function (record, search, https, format) {
  function beforeSubmitScript(context) {
    try {
      var currentRecord = context.newRecord;
      var entity = currentRecord.getValue({
          fieldId: "entity",
        });
      var name = currentRecord.getValue({
          fieldId: "initialtranid",
        });
      var id = currentRecord.getValue({
          fieldId: "id",
        });
      var isReorderd = currentRecord.getValue({
          fieldId: "custbody_jj_reorder_products",
        });
      if (isReorderd == 'T' || isReorderd == true) {
        
      var reorderStart = currentRecord.getValue({
          fieldId: "custbody_jj_reorder_start_date",
        });
      var formatStartDate = format.parse({‌value:reorderStart , type: format.Type.DATE});
      var reorderEnd = currentRecord.getValue({
          fieldId: "custbody_jj_reorder_end_date",
        });
      var formatEndDate = format.parse({‌value:reorderEnd , type: format.Type.DATE});
      var itemList = [];
      var lineItemCount = currentRecord.getLineCount({
        sublistId: "item",
      });
      if (isReorderd === 'T' || isReorderd === true) {
      var reorderRecord = record.create({
       type: 'customrecord_jj_reorder_chekout_items',
       isDynamic: true
   });
      reorderRecord.setValue({
          fieldId: 'custrecord_jj_re_sales_oder',
          value: id
        }); 
      reorderRecord.setValue({
          fieldId: 'custrecord_re_customer',
          value: entity
        }); 
      reorderRecord.setValue({
          fieldId: 'name',
          value: name
        }); 
      reorderRecord.setValue({
          fieldId: 'custrecord_re_order_end_date',
          value: formatEndDate
        }); 
      reorderRecord.setValue({
          fieldId: 'custrecord_re_order_start_date',
          value: formatStartDate
        });
      }
      }

      log.error('gdfgdfg', reorderRecord);
    } catch (error) {
      log.error('ERROR @ UES', error)
    }
  }
  return {
    beforeSubmit: beforeSubmitScript,
  };
});

Leave a comment

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