Execute Script Action#155
Conversation
|
✅ Valid PR for ActionPack Thank you for your contribution. This PR complies with the CONTRIBUTING.md. |
|
Hey @jiteshmalik, thanks a lot for taking a stab at it and the elaborate response. I did not get into the weeds, it was more to generate some ideas by our developer community (like your's), prompted by actions that our customers ask our Product Management team about 😃 Appreciate your efforts, I'll ask my better educated colleagues to take a look! |
SapphicFire
left a comment
There was a problem hiding this comment.
I really appreciate this contribution and the degree of thought and care put into the implementation. Great work
|
As mentioned in my comment, I greatly appreciate this contribution. You've thought through a lot of the risks inherent in this type of action, and introduced a great example implementation. At this stage, I am not comfortable introducing this action into the repository. This is not a reflection of your work or approach, but the danger and potentially destructive nature of such an action. However, I want to ensure that you are properly recognised for this. In the short term, I will add the |
#145 This request definitely made me pause and think through some important questions—such as who gets access to this, what privilege level the scripts run at, whether it opens doors for ACL bypasses, and how it aligns with compliance requirements like SOX or PCI-DSS. But honestly, the technical puzzle was interesting enough that I decided to dig into it anyway.
Implementation Challenge:
Turns out ServiceNow's JavaScript APIs make this trickier than expected. The eval() function only works in global scope, and GlideScopedEvaluator (which would be the "proper" scoped option) needs you to save the script to a GlideRecord first before it can run anything. There's no clean way to just execute a script string from memory in a scoped app—you either have to persist it to a table or work in global scope, and both of those options bring their own security headaches.
Solution Implemented:
I ended up building the custom action with a flexible approach that uses a temporary table to handle the GlideScopedEvaluator requirement:
Input Variables (6 total):
Output Variables (4 total):
This way, you get audit trails and execution metadata while working within ServiceNow's scoped API constraints.
Example (minimal):
Example (with custom audit field names):
Note: Logs will show the triggering user (from Flow context), but scripts execute in system context due to GlideScopedEvaluator isolation. The audit fields (if configured) capture the actual triggering user before execution.