
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2018 09:34 PM
Hi,
I have a mobile phone purchase catalog item, that has a workflow behind it for approvals etc. In the workflow I have a "Run Script" step that basically changes the state of the current record, but also adds "Additional Comments" to the record, the issue I have is the "Additional Comments" are added by the user that is running the workflow, so if I am logged in to the service portal as "Joe Bloggs", once I click submit a request item is created and the "Additional Comments" show up with the name of the logged in user.
I have added the following code
var origUser = gs.getSession().impersonate('42c32ed04f4c1b00c4a0cf401310c7b1');
current.state = '-5';
current.comments = "Awaiting Approval";
current.update();
var impersonate = gs.getSession().impersonate(origUser);
For admin users it works well, but for non-admin users, the comments get added as guest (see below), I have read that if I give users the impersonate role, then the issue will be resolved.
The problem is I don't want users to be able to impersonate other users, I only want this to work when the workflow is running, for the express purpose of adding comments (updates) to the activity stream.
Is there a better way to fix this or do it a better way?
Thanks in advance for any assistance you can offer.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 01:41 PM
John,
Workflows will execute based on the logged in user. Try this..
1. Add a 1 second timer at the beginning of your workflow. This will force it to run asynchronously by a system process.
2. Use a Set Values from the Utilities category instead of run script. Including a current.update() is not good practice in workflows.
You can leave your run script activity there for testing/backup but just don't have any connections to it. Hopefully this solves your challenge.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2018 10:15 PM
Hello John,
Have you tried without impersonation code?
Like this in workflow script -
current.state = '-5';
current.comments = "Awaiting Approval";
current.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 01:23 PM
Nayan,
Yes, if I remove the impersonate code, the comment does get added. However it looks like the logged in user has added it. The first screenshot below shows what I mean, without the impersonate code and logged in with my admin account (john_local.McLaughlin), the comment gets added to the activity stream but it looks like it has been added by my user so appears on the right hand side of the stream.
but when I use the impersonate code with my admin account, the comment is successfully added to the left hand side of the activity stream as shown in the next screen shot
So the impersonate code is working for any user that has the ability to impersonate another user, that is currently my admin staff, and to be honest I don't really want to allow other users to have the ability to impersonate, I just need that ability for this one workflow I am putting together.
My overall aim is to achieve the second screen shot above without giving my users the ability to impersonate others, as it is only for this particular workflow.
again thanks for any assistance you can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 01:41 PM
John,
Workflows will execute based on the logged in user. Try this..
1. Add a 1 second timer at the beginning of your workflow. This will force it to run asynchronously by a system process.
2. Use a Set Values from the Utilities category instead of run script. Including a current.update() is not good practice in workflows.
You can leave your run script activity there for testing/backup but just don't have any connections to it. Hopefully this solves your challenge.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2021 11:01 PM
The 1 sec timer worked like a charm.