This is what I can provide in the coding part from my end:
function beforeSubmit(scriptContext) { var salesorder = scriptContext.newRecord;
var discount = salesorder.getValue('discountitem');
if(discount == ''){
log.debug('Hi');
var discountSearch = search.load({
id : 'customsearch_cg_ue_discount_in_order' // ID of the saved search created.
});
var searchResult = discountSearch.run().getRange({
start: 0,
end: 5
});
for (var i = 0; i < searchResult.length; i++) {
var item = searchResult[i].getValue('itemid');
log.debug('I am here ' + item);
if(item == 'z10% Discount'){ // Assigning this discount line on SO form.
log.debug('I should print :' + item);
salesorder.setText('discountitem',item.id);
}
}
}
}