How to use the function checkForParamter

It is a function to validate a parameter. It will check if the parameter meets certain conditions for validity. The example of the code is shown below.

const checkForParameter = function checkForParameter(parameter) {
try {
if (parameter !== “” && parameter !== null && parameter !== undefined && parameter !== false &&
parameter !== “null” && parameter !== “undefined” && parameter !== ” ” && parameter !== ‘false’
&& parameter !== 0 && parameter !== ‘0’) {
return true;
}
}
catch (err) {
log.debug(“error@checkParameter”, err)
return false
}
}

const afterSubmit = (scriptContext) => {
try {
if (scriptContext.type === scriptContext.UserEventType.CREATE || scriptContext.type === scriptContext.UserEventType.EDIT) {
let currentRec = scriptContext.newRecord;
let temp;
let rwsMarketValue = currentRec.getValue({
fieldId: ‘custitem_jj_market_ahap1547’
});
if (checkForParameter(rwsMarketValue)) {
for (let i = 0; i < matchingFields.length; i++) {
let fieldValue = currentRec.getValue({
fieldId: matchingFields[i]
});

record.submitFields({
type: ‘inventoryitem’,
id: currentRec.id,
values: {
‘custitem_jj_rws_mkt_leader’: label
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});

else {
record.submitFields({
type: ‘inventoryitem’,
id: currentRec.id,
values: {
‘custitem_jj_rws_mkt_leader’: ”
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}

catch (err) {
log.debug(“error detected”, err);
}
}
return { afterSubmit }

Leave a comment

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