- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 06:21 AM
Dear Team,
There is a Record producer through which INC is created, and that record producer has a field named 'Location; this location is mapped with INC record creation to populate same Location to INC's Location field. (per below script)
Now, I need to auto-add the User to a watchlist of the INC record when it's submitted/created.
The User whom I want to auto-add to a watchlist of INC is the Manager of 'Contact' filled in the cmn_location table record (refer to below screenshot yellow highlighted manager should be auto-add to a watchlist of INC)
Please help me with the script or Business Rule to fulfil this requirement.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 06:58 AM
Hello rishabh31,
I have appended a Business Rule "Add Locations Manager to Watchlist" on the incident table that adds the Location Contact Manager to the watch list if available on incident creation.
If this solved your problem please mark as helpful. Otherwise feel free to leave a reply.
Best Regards
Dominik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 12:40 AM
Hello rishabh31,
Great that it is working for you now! I have looked at it on a PDI and changed the BR accordingly so that it should work now (see Attachment of this Comment). I want to note that that the .sys_id.toString() that you added is something that you should not do in Server Scripts as it is not in line with the ServiceNow Coding Best practices and less performant. The Information that we want to add here (the sys_id of the Manager) is already stored in the reference field (manager). The dot-walk to sys_id is thus unnecessary.
"The value of a reference field is a sys_id. When you dot-walk to the sys_id, the system does an additional database query to retrieve the caller_id record, then retrieves the sys_id. This can lead to performance issues. [...]"
Look here for further guidance on the Coding Best Practices on the ServiceNow Plattform: https://developer.servicenow.com/dev.do#!/guides/vancouver/now-platform/tpb-guide/scripting_technica...
I hope you have a good day!
Best Regards
Dominik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 06:58 AM
Hello rishabh31,
I have appended a Business Rule "Add Locations Manager to Watchlist" on the incident table that adds the Location Contact Manager to the watch list if available on incident creation.
If this solved your problem please mark as helpful. Otherwise feel free to leave a reply.
Best Regards
Dominik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 07:49 AM
Hi @Dominik Chiaia ,
Thanks I have tried the BR provided by you but its not working as Location's Contact's Manager is still not added on watchlist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 08:05 AM
@Dominik Chiaia Please ignore my last reply, it is working fine, just added 'sys_id.toString()'.
The Final BR Script would be
(function executeRule(current, previous /*null when async*/) {
if(current.watch_list.nil()) {
current.setValue("watch_list", current.location.contact.manager.sys_id.toString());
} else {
current.setValue("watch_list", current.getValue("watch_list") + "," + current.location.contact.manager.sys_id.toString());
}
})(current, previous);
Thanks marking your response correct and helpful😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 12:40 AM
Hello rishabh31,
Great that it is working for you now! I have looked at it on a PDI and changed the BR accordingly so that it should work now (see Attachment of this Comment). I want to note that that the .sys_id.toString() that you added is something that you should not do in Server Scripts as it is not in line with the ServiceNow Coding Best practices and less performant. The Information that we want to add here (the sys_id of the Manager) is already stored in the reference field (manager). The dot-walk to sys_id is thus unnecessary.
"The value of a reference field is a sys_id. When you dot-walk to the sys_id, the system does an additional database query to retrieve the caller_id record, then retrieves the sys_id. This can lead to performance issues. [...]"
Look here for further guidance on the Coding Best Practices on the ServiceNow Plattform: https://developer.servicenow.com/dev.do#!/guides/vancouver/now-platform/tpb-guide/scripting_technica...
I hope you have a good day!
Best Regards
Dominik