The error “Empty invocation target!” appears when attempting to hide sublist fields in the sales order.
Reason:
This error occurs because the field is not applied to the sales order form.
Solution:
To resolve the issue, retrieve the available sublist fields in the sales order and verify whether the field intended to be hidden is present in the form.
let sublistFields = newRecord.getSublistFields({ sublistId: 'item' });
log.debug('sublistFields', sublistFields);
for (let i = 0; i < fieldsToRestrict.length; i++) {
let sublistField = sublist.getField({ id: fieldsToRestrict[i] });
try {
if (sublistFields.includes(fieldsToRestrict[i])) {
sublistField.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});
}
} catch (error) {
log.error('Error hiding field', error);
}
}