Add comment via Wokflow as a different user

eican
Kilo Guru

We are building a workflow and within that workflow we are also checking if certain fields of the current record have a (valid) value.

In case that is not the case we are adding a work note to the record stating what they have to do (Basically what the workflow is waiting for) and the workflow goes in a "wait for" state.

 

If now the previous activity is an approval, then this work note is added in the context of the same user. (The Activity log shows "User A" added work note "Please add a valid due date"). Well, in fact not User A added that work note but the workflow did.

 

The current idea to address this is to impersonate another user (e.g. Dummy User) and then add the work note.

The work note shows up as user "Dummy User". But when the workflow now continues it is stuck and it seems it has lost its own original context.

Even if I impersonate the previous user it doesn't change anything.

 

To impersonate another user we use:

var origUser = gs.getSession().impersonate('sys_id of user record'); //return value is the current user

 

Error message is:

java.lang.ClassCastException: org.mozilla.javascript.UniqueTag cannot be cast to java.lang.String
Caused by error in Script Include: 'Workflow' at line 32

29:
30: // make sure we have the real record to run the workflow against
31: if (record.getTableName() == record.getRecordClassName()) {
==> 32: this.workflow.runFlows(record, operation);
33: record.update();
34: } else {
35: var realRecord = new GlideRecord(record.getRecordClassName());

 

Did anyone come across this? Or knows a different approach to add a comment/work note to a task record which is not in the current users' name?

1 ACCEPTED SOLUTION

JordanLind
Kilo Guru

Insert a Timer Activity before this comment/work note workflow activity .   You can set the timer to a short duration such as 5 or 10 seconds.   Once the work note activity fires, the comment/work note user should be "System".


View solution in original post

1 REPLY 1

JordanLind
Kilo Guru

Insert a Timer Activity before this comment/work note workflow activity .   You can set the timer to a short duration such as 5 or 10 seconds.   Once the work note activity fires, the comment/work note user should be "System".