- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 05:20 AM
Hello, ServiceNow Gurus,
Say I have a Business Rule, and that Business Rule calls into a Script Include, and that Script Include writes a message to the System Log...
Is it possible for the script include to figure out, at runtime, its own sys_id? And include that in the log statement?
I know that I can manually log the sys_id by writing my own log function and passing in the "hard-coded" sys_id, but that's not what I want. I want for the script itself to magically determine the sys_id of the container it lives in. Is that possible? And if so, how please?
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 05:25 AM
Hi,
no you cannot get the sysId of the BR automatically and log it.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 08:24 PM
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 07:03 AM
Hi,
No we can't retrieve the business rule sys_id from script include we don't have such method.
Assumption:
for example we have object to get sysid of business rule but for the same script include we have multiple business rules which one we will get from that.
Hope you got my point.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022 05:07 AM
I just want the sys_id of the container, the Script Include record itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 09:05 PM
You can get it by purposely throwing and catching an error, then extracting it from the stack trace.
function getThisScriptIncludeSysID() {
try {
undefinedObject.purposelyFail();
} catch (e) {
var m = e.stack.match(/sys_script_include\.([0-9a-f]{32})\.script/);
if (m) return m[1];
}
}