mg2017
07/01/2024, 2:02 PMfunction beforeSubmit(context) {
if (context.type === context.UserEventType.CREATE || context.type === context.UserEventType.EDIT) {
const newRecord = context.newRecord;
var hasInventoryItem = false;
const lineCount = newRecord.getLineCount({sublistId: 'item'});
for (let i = 0; i < lineCount; i++) {
const itemType = newRecord.getSublistValue({
sublistId: 'item',
fieldId: 'itemtype',
line: i
});
if (isInventoryItem(itemType)) {
hasInventoryItem = true;
break;
}
}
if (!hasInventoryItem) {
log.debug("No inventory items found, unset intrastat fields");
const fieldsToUnset = [
'custpage_country_of_origin_temp',
'custbody_transaction_region',
'custpage_delivery_terms',
'custbody_notc',
'custpage_mode_of_transport'
];
fieldsToUnset.forEach(fieldId => {
log.debug({title: `Before Unsetting ${fieldId}`, details: newRecord.getValue({fieldId: fieldId})});
});
// Unset the fields
fieldsToUnset.forEach(fieldId => {
newRecord.setValue({fieldId: fieldId, value: '' });
});
fieldsToUnset.forEach(fieldId => {
log.debug({title: `After Unsetting ${fieldId}`, details: newRecord.getValue({fieldId: fieldId})});
});
}
}
}
mg2017
07/01/2024, 2:24 PMAnthony OConnor
07/01/2024, 3:02 PMAnthony OConnor
07/01/2024, 3:03 PMAnthony OConnor
07/01/2024, 3:06 PMmg2017
07/01/2024, 3:11 PMAnthony OConnor
07/01/2024, 3:12 PMAnthony OConnor
07/01/2024, 3:12 PMAnthony OConnor
07/01/2024, 3:13 PMmg2017
07/01/2024, 3:16 PMmg2017
07/01/2024, 3:28 PMbattk
07/01/2024, 4:32 PM