In certain scenarios, it is essential to prevent users from editing Sales Orders (SO) when specific conditions are met, such as when a pick task is associated with the order. This ensures the integrity of the order fulfillment process, particularly when integrated with third-party applications like RF Smart.
Implementation Steps:
- Open Orders Search Feature:
- A custom search can be configured in the dashboard to display all open Sales Orders. This search feature allows users to easily view their open orders.
- Integration with Third-Party Applications:
- The RF Smart application, for instance, may add a subtab within the Sales Order record. When a pick task is associated with a Sales Order, details are reflected under this subtab.
- Editing Restriction Logic:
- A
User Event Scriptcan be developed to monitor the Sales Order during the edit event. If the script detects any associated pick tasks under the relevant subtab, it restricts the user from editing the Sales Order. - The script checks the presence of sublist fields under the
custpage_rfs_taskssubtab. If the sublist exists and contains data (indicating an associated pick task), an error message is triggered, preventing the user from making changes.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/currentRecord', 'N/record', 'N/search', 'N/runtime'],
(currentRecord, record, search, runtime) => {
const beforeLoad = (scriptContext) => {
try {
if (scriptContext.type === scriptContext.UserEventType.EDIT) {
const soRecord = scriptContext.newRecord;
let currentUser = runtime.getCurrentUser().id;
// Restrict edit for specific user role or user ID
if (currentUser == "197177") {
let objSublist = soRecord.getSublistFields({
sublistId: 'custpage_rfs_tasks'
});
let listLen = objSublist.length;
if (listLen != 0) {
throw 'Items of this bill have been reimbursed.</br>Editing this record is not allowed.';
} else {
log.debug("RF-SMART subtab is not present");
}
}
}
} catch (e) {
log.error("Error in beforeload", e);
}
}
return { beforeLoad }
});