Business Rule Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2024 10:55 AM
We have a Business Rule on our sn_customerservice_change_request table. From a Change Request that has already been created, if a MAINT task is created (Related List) from the Change Request, it will take values from the Change Request and add them to the MAINT task being created. After the MAINT is created, and when the State of the MAINT Task is changed from New to Proposed, it will add the Account name, and it's supposed to look at the Account associated with the MAINT Task, and add the users who have been added to the MAINT Approvers and MAINT CC list fields, and add them to the Customer Watch List on the MAINT Task. It's adding the users from the MAINT CC list field to the Customer Watch List on the MAINT, but it's not adding the MAINT Approvers to the Customer Watch List on the MAINT. Below is the script for the Business Rule being used.
(function executeRule(current, previous /*null when async*/ ) {
var parentAccount = current.parent.account.getRefRecord();
g_scratchpad.change_request = {
account: {
sys_id: parentAccount.getUniqueValue() || "",
name : parentAccount.getValue('name') || "",
u_maint_cc: parentAccount.getValue('u_maint_cc') || "",
u_maint_approvers: parentAccount.getValue('u_maint_approvers') || ""
},
short_description: current.parent.short_description.toString(),
state: {
value: current.parent.state.toString(),
displayValue: current.parent.state.getDisplayValue()
}
};
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2024 11:12 AM - edited ‎05-15-2024 11:13 AM
Hi @MStritt ,
Can you please try the below code to solve the issue,
The code shared by you it does not show the logic that actually manipulates the Customer Watch List on the MAINT task, that could be the reason.
Please take a look and try to implement the below code-
(function executeRule(current, previous /*null when async*/ ) {
if (current.state.changesFrom('new') && current.state.changesTo('proposed')) {
var changeReq = current.parent.getRefRecord();
if (changeReq && changeReq.account) {
var account = changeReq.account.getRefRecord();
var watchList = '';
var ccList = account.getValue('u_maint_cc');
if (ccList) {
watchList += ccList;
}
var approversList = account.getValue('u_maint_approvers');
if (approversList) {
if (watchList.length > 0) {
watchList += ',' + approversList;
} else {
watchList = approversList;
}
}
// Update the Customer Watch List on the MAINT Task
if (watchList) {
current.u_customer_watch_list = watchList;
}
current.update();
}
}
})(current, previous);
If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2024 11:18 AM
Thanks Sanjay. Then I might be looking at the wrong Business Rule. It does add the MAINT CC users to the MAINT Task Customer Watch List, just not MAINT Approvers. Let me look further, to see if there's some other logic controlling this.