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 07:15 AM
Rather than a Business Rule, you can run this script as a scheduled job - nightly, weekly, or whatever close RITMs that were opened by users who are now inactive... In the scheduled job setup there is an option to run the script as a certain user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:50 AM
My suggestion would be to not use "setWorkflow(false)" nor "autoSysFields(false)" when you are updating a real production data as part of user deactivation process. Those methods are helpful in case you are mass-updating data to just fix one field value for example. But in standard business process dangerous - e.g., turning off business rules might end up that a) SLAs running on RITM will not be completed, b) Metric Instances on RITM might not be completed and so on... many data inconsistency issues might pop up.
If the only problem is that your name is there - which is probably because you deactivated the user in your session, and onAfter BR run also under your session, then try to decouple the actions of 1) who is deactivating the user, 2) who is updating the RITMs. You can try "Async BR" if that is decoupling it from your session, or you could generate an event (like "sys_user.deactivated") in onAfter BR and have "Script Action" to be executed out of that event - then it would probably run under "system". I did not test any of these, but maybe it can help you.
Regards,
Dominik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:41 AM
ideally let the name be shown of that user who performs the action via the business rule.
what's your concern?
why you want to want with some other user?
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:42 AM - edited 03-10-2025 06:46 AM
you need to show updated by system?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 06:51 AM
Is this line " grScReqItem.autoSysFields(false);" working ? ---This is the only issue it is not working