1.0 to 2.0 script conversion with sample code

This 1.0 code
function setCustomerDiscounts(type) {
  log.debug('setCustomerDiscounts', '==START==');
  try {
    if (!isValidForm()) return;


    var recType = nlapiGetRecordType();
    var recId = nlapiGetRecordId();
    var lines = getTransactionLines(recId, recType);
    log.audit('Doc No', 'Doc No ' + nlapiGetFieldValue('tranid'));
    log.debug('lines', JSON.stringify(lines));


    if (ObjectUtils.isEmpty(lines)) return;


    var header = {};
    header.custId = nlapiGetFieldValue('entity');
    header.location = nlapiGetFieldValue('location');
    header.branch = nlapiGetFieldValue('custbody_cseg_au_branch');
    header.tranDate = nlapiGetFieldValue('trandate');
    header.projectId = nlapiGetFieldValue('custbody_au_project');
    // header.branchPriceLvl = getLocationPriceLevel(header.location);
    header.branchPriceLvl = getBranchPriceLevel(header.branch);


    log.debug('header', JSON.stringify(header));


    var pricingCustomerId = checkParentCompanyPricing(header.custId);
    log.debug('pricingCustomerId', pricingCustomerId);
    header.custId = pricingCustomerId;


    fetchPricingInformation(header, lines);
    // log.debug('pointsBEFORE Remaining', 'Points pointsBEFORE Remaining - ' + nlapiGetContext().getRemainingUsage());


    setDiscountOnLines(recType, recId, header);
    log.debug('points END Remaining', 'Points Remaining - ' + nlapiGetContext().getRemainingUsage());
  } catch (e) {
    var errorMessage = 'Error in setCustomerDiscounts';
    log.error(errorMessage, 'details: ' + e.toString());
  }
  log.debug('setCustomerDiscounts', '==END==');
}

2.0 script 

 function setCustomerDiscountFunction(newRecord, recType, recId, formId) {
            try {
                if (Object.values(CUSTOMER_PRICING_FORMS).includes(formId)) {
                    let lines = getTransactionLines(recId, recType);
                    if (lines.length <= 0) {
                        return;
                    }
                    let header = {};
                    header.custId = newRecord.getValue('entity');
                    header.location = newRecord.getValue('location');
                    header.branch = newRecord.getValue('custbody_cseg_au_branch');
                    header.tranDate = newRecord.getValue('trandate');
                    header.projectId = newRecord.getValue('custbody_au_project');
                    if (header.branch) {
                        header.branchPriceLvl = getBranchPriceLevel(header.branch);
                    }
                    let pricingCustomerId = checkParentCompanyPricing(header.custId);
                    header.custId = pricingCustomerId;
                    fetchPricingInformation(header, lines);
                    setValuesOnLines(header, recObj, discountData, isAuWtCalc, isDiscountCalc);
                }
            } catch (error) {
                log.error('error @setCustomerDiscountFunction', error);
            }
        }

Leave a comment

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