Workflow switching to run as 'System' user if adding a Timer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2018 04:01 AM
Hi,
I initiate a workflow by having a scheduled job running as a user named 'uCMDB_Integration'.
In the workflow I have 2 scripts where I split the transformation of 10 import sets (5 transformations started in each script):
Both are run as the user 'uCMDB_Integration as seen here in the system log:
However, if I add a Timer between the 2 scripts in the workflow:
The 2nd script switches to run as the 'System' user:
How do I avoid this?
Regards,
Kristian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2018 07:11 AM
Expected behavior as noted. The only possibility might be a wait for condition as noted, but it'll be tricky. You'll need something in one of the first set of transforms to 'nudge' the workflow. Since the first set of transforms is running as uCMDB_Integration, the nudge is as that user. In the wait for condition, you'll need to evaluate something. Maybe that the 5 transforms are complete?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2018 07:20 AM
There is one other possibility I remembered. Using Impersonation.
var prevUser = gs.getSession().impersonate('cc58d373dbe20344e7f7f4331f96195f'); //Sys ID of the User you want to Impersonate
// Run your transforms here
gs.getSession().impersonate(prevUser); //NEVER Forget this line, returning to the System user. Otherwise you might see odd behavior where other worked picked up at the same time has your uCMDB_Integration account tagged to it.
I'm not sure how well supported doing this in scripts is, but we've used it in a few places. I will say again though, never forget to end your impersonation (by impersonating back to prevUser)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 03:07 AM
Hmmm.
I could add a wait condition which uses GlideRecord to check whether the first set of transforms have completed with status=loaded.
But it doesn't seem possible to use a wait condition like that. Seems it can only be triggered by an external event like a field on the workflow record being updated.
Question is how I would trigger an update of such a field on the workflow record if not by having a timer in the workflow repeating an 'IF' activity which uses glideRecord to check when the first set of transform have completed and then updates the field thus triggering the wait condition activity?
Can I instead of a timer run a script in the workflow running a while loop until the first set of transforms have completed?
I'm not that familiar with JavaScript. Can I use 'sleep' to repeat the while loop until the transforms have completed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2018 04:53 AM
That is where the nudge comes in. The nudge is the only thing that could allow you to keep the same user, the wait for condition by itself won't do that.
If you go to the workflow context table, there is a UI Action 'Nudge', that has some of the code. You'll have to get the workflow context id somewhere, maybe just querying for the active workflow.
As I mentioned though, the script that nudges your workflow forward has to be part of the transforms (on complete, or on start.. whatever you are looking for) that are already running as uCMDB. If the nudge comes from just another system event, then you'll still get system administrator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2018 12:57 AM
I decided to use gs.sleep(180000) in a while loop instead of the timer.
That seems to work and it allows following activities in the workflow to continue to run as my uCMDB_integration user.
Do you see any issues using gs.sleep() in a workflow script?