Delete the value of a field in the custom record when a related sales order will be deleted.

(record, search) => {

const beforeSubmit = (scriptContext) => {
try{
if (scriptContext.type === scriptContext.UserEventType.DELETE) {
let salesOrderId = scriptContext.newRecord.id;
let openBoxSearch = search.create({
type: ‘customrecord_jj_open_box_item_log1108’,
filters: [
[‘custrecord_jj_so_number_openboxitem1749’, ‘anyof’, salesOrderId]
]
});
openBoxSearch.run().each(function(result) {
let openBoxId = result.id;
record.submitFields({
type: ‘customrecord_jj_open_box_item_log1108’,
id: openBoxId,
values: {
‘custrecordjj_item_sold_openboxlog1203’: false,
‘custrecord_jj_so_date_openboxitem1749’: null
}
});
return true;
});

}
}
catch(err){
log.error(“error in Beforesubmit”, err);
}
}
return { beforeSubmit}
});


Leave a comment

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