The CreatorCon Call for Content is officially open! Get started here.

Workflow - adding additional comments

JohnMMcLaughlin
Tera Contributor

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.

find_real_file.png

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.

1 ACCEPTED SOLUTION

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.


View solution in original post

5 REPLIES 5

JohnMMcLaughlin
Tera Contributor

Michael,



Thanks for the assistance, I've done a quick test and it looks to do exactly what I am after, I'll do some further testing before marking this as answered.