Version: eXtendOrders 2.1.0 and above
Audience: Administrator, Developer

Overview

In eXtendOrders 2.0, when you generate or regenerate line items using the Generate Lines or Create Lines Server-Side buttons, all item lines are removed and new lines are added as per the Order Imprint Configuration (OIC) information present on the record. In this process, if you have provided values against custom column fields, it will be lost during the regeneration process (as the OIC information doesn't have context of those values).

To retain custom column field values from being lost during the regeneration process, the lineItemBackupObjectBeforeDelete() function is included in the suite_orders_custom_hook_functions.js file.

By providing custom column field internal id(s) in the lineCustomFieldIDs array, as shown in the example below, those values will be retained and added back to the regenerated line items.
/**
     * @param {Object} args
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.lineIndex
     * @prop  {Object} args.itemIdAndCustomFieldMap
     */
    function lineItemBackupObjectBeforeDelete(args) {
        // Add here the line item field id which needs to be backed up for re-spinning.
        var lineCustomFieldIds = [
          'custcol_smt_fos_line_id',
          'custcol_smt_fos_order_id',
          'custcol_smt_fos_ship_num_id',
          'custcol_smt_gcamount',
          'custcol_smt_gc_item_id',
          'custcol_smt_gclineid',
          'custcol_smt_gcorderid',
          'custcol_smt_gcquantity',
          'custcol_smt_gc_type',
          'custcol_smt_qt_line_id',
          'custcol_smt_qt_order_id',
          'custcol_smt_art_line_id',
          'custcol_smt_art_order_id'
        ];
        var itemIdAndCustomFieldMap = args.itemIdAndCustomFieldMap || {};
        var currentRecord = args.currentRecord;
        var sublistId = args.sublistId;
        var lineIndex = args.lineIndex;
        var isDynamic = currentRecord.isDynamic;
        var getterMethod = isDynamic ? 'getCurrentSublistValue' : 'getSublistValue';
        isDynamic ? currentRecord.selectLine({ sublistId: sublistId, line: lineIndex }) : '';
        var item = currentRecord[getterMethod]({ sublistId: sublistId, fieldId: 'item', line: lineIndex });
  
        if (currentRecord.getSublistFields) {
          var allSublistFields = currentRecord.getSublistFields({ sublistId: 'item' }) || [];
          lineCustomFieldIds = allSublistFields.filter(function (field) {
            if (field.indexOf('custcol') === 0) {
              return field;
            }
          });
        }
  
  
        var currentFieldValue;
        var lineItemObject = {};
  
        if (!itemIdAndCustomFieldMap[item]) {
          itemIdAndCustomFieldMap[item] = [];
        }
  
        lineCustomFieldIds.forEach(function (lineCustomFieldId) {
          currentFieldValue = currentRecord[getterMethod]({ sublistId: sublistId, fieldId: lineCustomFieldId, line: lineIndex });
  
          if (!currentFieldValue) {
            return;
          }
  
          lineItemObject[lineCustomFieldId] = currentFieldValue;
        });
  
        itemIdAndCustomFieldMap[item].push(lineItemObject);
        return itemIdAndCustomFieldMap;
      }
  

Configuration

The functions below can be used to set values on different types of line items based on eXtendOrders functionality: 

  1. Setting values on Blank Items:
    /**
     * @param {Object} args
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.oicLineSublistWrapper
     * @prop  {Object} args.lineItemSublistWrapper
     */
    function oicMainToLineItem(args) {
        var currentRecord = args.currentRecord;
        var oicLineSublistWrapper = args.oicLineSublistWrapper;
        var lineItemSublistWrapper = args.lineItemSublistWrapper;
      }
  2. Setting values on Blank Surcharge Items:
    /**
     * @param {Object} args
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.oicLineSublistWrapper
     * @prop  {Object} args.lineItemSublistWrapper
     * @prop  {Object} args.lineItemBackupBeforeDelete
     */
    function itemSurchargeToLineItem(args) {
        var currentRecord = args.currentRecord;
        var oicLineSublistWrapper = args.oicLineSublistWrapper;
        var lineItemSublistWrapper = args.lineItemSublistWrapper;
        var lineItemBackupBeforeDelete = args.lineItemBackupBeforeDelete || {};
      }
  3. Setting values on Setup line Items:
    /**
     * @param {Object} args
     * @prop  {Object} args.oicLineSublistWrapper
     * @prop  {Object} args.lineItemSublistWrapper
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.lineItemBackupBeforeDelete
     * @prop  {Boolean} args.allowPmsColorSelection
     */
    function decoSetupToLineItem(args) {
        var lineItemSublistWrapper = args.lineItemSublistWrapper;
        var currentRecord = args.currentRecord;
        var oicLineSublistWrapper = args.oicLineSublistWrapper;
        var lineItemBackupBeforeDelete = args.lineItemBackupBeforeDelete || {};
      }
  4. Setting values on First Run Line Items:
    /**
     * @param {Object} args
     * @prop  {Object} args.oicLineSublistWrapper
     * @prop  {Object} args.lineItemSublistWrapper
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.lineItemBackupBeforeDelete
     */
    function decoFirstRunToLineItem(args) {
        var currentRecord = args.currentRecord;
        var lineItemSublistWrapper = args.lineItemSublistWrapper;
        var oicLineSublistWrapper = args.oicLineSublistWrapper;
        var lineItemBackupBeforeDelete = args.lineItemBackupBeforeDelete || {};
      }
  5. Setting values on Additional Run Line Items:
    /**
     * @param {Object} args
     * @prop  {Object} args.oicLineSublistWrapper
     * @prop  {Object} args.lineItemSublistWrapper
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.lineItemBackupBeforeDelete
     */
    function decoAddRunToLineItem(args) {
        var currentRecord = args.currentRecord;
        var lineItemSublistWrapper = args.lineItemSublistWrapper;
        var oicLineSublistWrapper = args.oicLineSublistWrapper;
        var lineItemBackupBeforeDelete = args.lineItemBackupBeforeDelete || {};
      }
  6. Setting values on Imprint Surcharge Line Items:
    /**
     * @param {Object} args
     * @prop  {Object} args.oicLineSublistWrapper
     * @prop  {Object} args.lineItemSublistWrapper
     * @prop  {Object} args.currentRecord
     * @prop  {Object} args.lineItemBackupBeforeDelete
     */
    function decoImprintSurchargeToLineItem(args) {
        var currentRecord = args.currentRecord;
        var lineItemSublistWrapper = args.lineItemSublistWrapper;
        var oicLineSublistWrapper = args.oicLineSublistWrapper;
        var lineItemBackupBeforeDelete = args.lineItemBackupBeforeDelete || {};
      }

Note: For client-side line item generation, the script will select column fields from the lineCustomFieldIds array. For server-side line item generation, the script will pick all custom column fields.