Add automated comments/updates as Admin user instead of last user

Janel2
Mega Expert

When updating the comments, work_notes, or whatever fields, via a Workflow, UI Action, Business Rule, etc. is there a way to have the updates be added (at least appear to be added) as the the Admin or some other system user?

A bunch of our UI Actions, jobs, BR's, and especially workflows, will update a record with a current status or some other user-friendly update.   Like if a manager approval is required, a quick "Manager approval is required" will be added as a comment or work note.   The problem is, the comment/update appears as the user that initiated that action, even if it is the system technically writing it.

This confuses our users, especially on more complex updates referencing other tables/tasks (really, totally, especially when wait for activities are involved!).   Users think that a workflow update is actually coming from a real user and not the workflow, because, well, the update was added using a the name of a real user.

I mostly get why it is like that (because technically they are initiating the update, etc. etc.).

For the love of Pete, please don't tell me this has to be a full blown impersonation (and likely requires the user initiating the update to have the role).

7 REPLIES 7

Prasun
Giga Guru

Hello,



Create an user called "Admin" or "System Administrator" and copy the sys_id.


In the workflow write this piece of code before you update the work_notes/comments



gs.getSession().impersonate('sys_id of the user');



current.work_notes('My Work Notes');


current.update();



Hope it helps.


That works, but has one major problem.   When I hit the workflow activity with the impersonate, it logs me out, which I kind of expected with gs.getSession.


I feel like the entire workflow would need to be impersonated, but I'm not sure how I would do a "run as" for a workflow.



That also makes me question how workflows work anyways since I can execute all sorts of scripts in a workflow as a non-privileged user.


You have to save the context of the impersonation as a variable, then after your current.update(), impersonate back to the original user.



//now impersonate saving original user id


var origUser = gs.getSession().impersonate('sys_id of user to impersonate');


current.comments = 'My comment here';


current.update(); //w/o a current.update() it doesn't save the worknote, and impersonation was for naught


//switch back to original user


var impersonated = gs.getSession().impersonate(origUser);


Thank you for that information.   I was able to add the following to a run script block in my workflow and it worked great, once I found the sys_id: (I was just trying to add work notes to the RITM on Istanbul)



gs.getSession().impersonate('Sys_ID');


current.work_notes ="Works"



Thanks again,



Gary McCullough


Service Automation Manager