/** * @description To format the Date Object into the given type/format * @param {Date} dateObj * @param {String} type * @returns {boolean|String} */ function formatDate(dateObj, type) { let dateAsKeys = splitDate(dateObj); if (dateAsKeys) switch (type) { case ‘MM/DD/YYYY’: ; case ‘M/D/YYYY’: return dateLogic.changeDateFormat(dateAsKeys, type, ‘/’); case ‘D/M/YYYY’: ; case ‘DD/MM/YYYY’: return changeDateFormat(dateAsKeys, type, ‘/’);… Continue reading Change date format
Category: SuiteScript Functions
SuiteScript Functions related articles will be posted in this category
Generate date object with the given date
/** * To generate Date Object with the given data * @param {[Number,Number,Number]} dataArray * @returns {Date} */ function generateDate(dataArray) { if (dateLogic.checkDateFormat(dataArray)) return new Date(Number(dataArray[0]), Math.abs(Number(dataArray[1]) – 1) % 12, dataArray[2]); return new Date(‘false’); } /** * @description To check whether the given date is in format of [Number,Number,Number]. ie, [YYYY,MM,DD] * @param {dateArray}… Continue reading Generate date object with the given date
Function accepts UTF_8 format and returns hexadecimal value of input
function encodingString ( params ) { try { let hexEncodedString = encode.convert( { string: params, inputEncoding: encode.Encoding.UTF_8, outputEncoding: encode.Encoding.HEX } ); return ( hexEncodedString ) } catch ( e ) { log.error( “error@encodingString”, e ) } }
Function to get the length of the parameters and convert the string to hex value
function getLength ( lengthparam ) { try { let length = lengthparam.length let orgLength = Number( length ) / 2 let hexString = orgLength.toString( 16 ) if ( hexString.length < 2 ) { hexString = “0” + hexString; } return hexString } catch ( e ) { log.error( “error@getLength”, e ) } }
Function to Render Template File
Function to remove duplicates from the array
Function to remove duplicates from the array
How to change currency sign into different symbol
If we have to change the currency sign or have to put different currency sign there. Then we can use this method there for getting the values. After assigning the currency just call it before the value where we want to put. For Eg: ${currencyType}
Convert Array to CSV
/** * Converts a value to a string appropriate for entry into a CSV table. E.g., a string value will be surrounded by quotes. * @param {string|number|object} theValue * @param {string} sDelimiter The string delimiter. Defaults to a double quote (“) if omitted. */function toCsvValue(theValue, sDelimiter) { try { var t = typeof (theValue), output;… Continue reading Convert Array to CSV
Divide Array to Chunks
/** * Dividing into array of arrays. * @param array Array to be divided * @param size length of trimmed array * */ function chunkArray(array, size) { try { let result = [] for (let i = 0; i < array.length; i += size) { let chunk = array.slice(i, i + size) result.push(chunk) } log.debug(‘result’,… Continue reading Divide Array to Chunks
Item search for getting available Bins for an item
/** *@description Available bin search – This function will return object of bin name and their quantity * @param itemName Name of the item * @return {Object} */function availableBinSearch(itemName) { try { var itemSearchObj = search.create({ type: “item”, filters: [ [“name”, “is”, itemName.toString()], “AND”, [“inventorydetail.binnumber”, “noneof”, “@NONE@”], “AND”, [“binonhand.quantityavailable”, “greaterthan”, “0”] ], columns: [ search.createColumn({… Continue reading Item search for getting available Bins for an item