Script not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:13 AM
Hi all
I am using below business rule on user table after update and active changes to false, everything is working fine state getting update worknotes getting updated but autosysfields not working, please suggest
(function executeRule(current, previous /*null when async*/ ) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:43 AM
can you try this
(function executeRule(current, previous /*null when async*/) {
var grScReqItem = new GlideRecord('sc_req_item');
grScReqItem.addEncodedQuery("cat_item=32524947c32b9a1062c17ebdc00131a5^stateNOT IN3,4,7^requested_for=" + current.sys_id);
grScReqItem.query();
while (grScReqItem.next()) {
grScReqItem.setWorkflow(false);
grScReqItem.autoSysFields(false);
// Update work notes without including the user's name
grScReqItem.work_notes = "RITM is closed incomplete as the requestor has been deactivated.";
grScReqItem.state = "4";
grScReqItem.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:51 AM
tried with your code state is getting updated only , then nothing happens worknotes also no updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:55 AM
I will recommend not using those 2 lines and let it be audited and let subsequent logic run whenever RITM state is getting updated.
This will help from audit point of view as well.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader