Hey everyone, I could use some help on this: I ma...
# suitescript
w
Hey everyone, I could use some help on this: I made a small change to a 2.x suitescript that was working before I made changes, but now Webstorm will not upload the changed script due to a
missing ; before statement
This is the code:
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/log'],
/**
 *
 *
 * @param {log} log
 */
function(log) {

	function getPriceLevels() {
		var arrPriceLevels = [];
		var pricelevelSearchObj = search.create({
			type: 'pricelevel',
			//filters: filter,
			columns:
				[
					search.createColumn({name: "name"})
				]
		});
		var searchResultCount = pricelevelSearchObj.runPaged().count;
		log.debug("pricelevelSearchObj result count", searchResultCount);
		pricelevelSearchObj.run().each(function (result) {
			// .run().each has a limit of 4,000 results
			if (result.id) {
				var obj = {};
				var id = result.id;
				var name = result.getValue('name');
				obj.name = name;
				obj.id = id;
				arrPriceLevels.push(obj);
			}

			return true;
		});

		return arrPriceLevels;
	}
   
	function getGsaPriceLevelIds() {
		let GsaPriceLevelIds = [4,23,3,60];	//Dealer, eCompanyStore, Promotional, State of New Jersey
		let priceLevels = getPriceLevels();
		priceLevels.forEach(function (priceLevel) {
			if (priceLevel.name.indexOf("GSA") === 0) {
				//name starts with the letters GSA
				GsaPriceLevelIds.push(parseInt(priceLevel.id));
			}
		});
		return GsaPriceLevelIds;
	}
	
    /**
     * Function definition to be triggered before record is loaded.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.newRecord - New record
     * @param {Record} scriptContext.oldRecord - Old record
     * @param {string} scriptContext.type - Trigger type
     * @Since 2015.2
     */
    function beforeSubmit(scriptContext) {
    	var GSApriceLevelIds = getGsaPriceLevelIds();
    	var recItem = scriptContext.newRecord;
    	var lowestLastColumnCommercialPrice = '0';
    	var priceRowsCnt = recItem.getLineCount({
    		sublistId: 'price'
    		});
    	
    	log.debug({
    		title: 'Price Rows Count',
    		details: priceRowsCnt
    	});
    	
    	var pricecolumnsCnt = recItem.getMatrixHeaderCount({
    		sublistId: 'price',
    		fieldId: 'price'
    	});
    	
    	log.debug({
    		title: 'Price Columns Count',
    		details: pricecolumnsCnt
    	});
    	
		for (var k=0; k < priceRowsCnt; k++) {

			var pricelevelId = recItem.getSublistValue({
				sublistId: 'price',
				fieldId: 'pricelevel',
				line: k
			});
			
			log.debug({
	    		title: 'Price level ID at Line ' + k,
	    		details: pricelevelId
	    	});
	    	
			if (!GSApriceLevelIds.contains(pricelevelId)) {
				for (var l=0; l < pricecolumnsCnt; l++) {
					var price = recItem.getMatrixSublistValue({
						sublistId: 'price',
						fieldId: 'price',
						line: k,
						column: l
					});
					log.debug({
			    		title: 'Price at Price Level ID ' + pricelevelId + ' Line: ' + k + ' Col: ' + l,
			    		details: price
			    	});
			    	
					if (lowestLastColumnCommercialPrice == 0 && price) {
						lowestLastColumnCommercialPrice = price;
					}
					//nlapiLogExecution('DEBUG', 'Columns Count', pricecolumnsCnt);
					//nlapiLogExecution("DEBUG", 'price in loop: ' + (k/1)+1 + " : " + l, price + ' ' + lowestLastColumnCommercialPrice + ' ' + typeof(lowestLastColumnCommercialPrice));
					if (price && price/1 < lowestLastColumnCommercialPrice/1) {
						
						log.debug({
				    		title: 'Price is lower than ' + lowestLastColumnCommercialPrice,
				    		details: price
				    	});
				    	
						lowestLastColumnCommercialPrice = price;
						//nlapiLogExecution("DEBUG", 'price in loop: ' + k+1 + " : " + l, price + ' ' + lowestLastColumnCommercialPrice + ' ' + typeof(lowestLastColumnCommercialPrice));
					}
				}
			}
		}
    	if (lowestLastColumnCommercialPrice > 0) {
    		recItem.setValue({
			fieldId: 'custitem_lowest_commercial_price',
			value: lowestLastColumnCommercialPrice.toFixed(2)
    		});
    		log.audit({
    			title: recItem.getValue({fieldId:'itemid'}) + ' Updated',
    			details: 'Lowest Commercial Price: ' + lowestLastColumnCommercialPrice
    		});
    	}
		
    }

    /**
     * Function definition to be triggered before record is loaded.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.newRecord - New record
     * @param {Record} scriptContext.oldRecord - Old record
     * @param {string} scriptContext.type - Trigger type
     * @Since 2015.2
     
    function afterSubmit(scriptContext) {

    }
	*/
    return {
        //beforeLoad: beforeLoad,
        beforeSubmit: beforeSubmit
        //afterSubmit: afterSubmit
    };

});

if (!Array.prototype.contains) {
	Array.prototype.contains = function(obj) {
		var i = this.length;
		while (i--) {
			if (this[i] == obj) {
				return true;
			}
		}
		return false;
	};
}
I don't see where a semicolon is missing and Webstorm did not prompt for any errors in the code
d
here it is in a snippet (so it has syntax highlighting)
b
Use
Copy code
@NApiVersion 2.1
👍 1
w
OMG
thank you
b
let
is a feature only available in suitescript 2.1
w
Ha, ok. I thought I put
var
's in
b
Copy code
function getGsaPriceLevelIds() {
  let GsaPriceLevelIds = [4, 23, 3, 60]; //Dealer, eCompanyStore, Promotional, State of New Jersey
  let priceLevels = getPriceLevels();
  priceLevels.forEach(function (priceLevel) {
    if (priceLevel.name.indexOf("GSA") === 0) {
      //name starts with the letters GSA
      GsaPriceLevelIds.push(parseInt(priceLevel.id));
    }
  });
  return GsaPriceLevelIds;
}