Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

gs.getUserId() return the wrong current user

Lhora Alvarez
Tera Sage

Hi all!

There's a problem with getUserId().

 

I have a business rule that will trigger when userA approves a record submitted by userB.

When approved, the business rule will post a work_note to the record. The author is expected to be userA because he is the one who approved it. But when I checked the record, userB is the author instead of userA.

 

When printing the userId of the current loggedin user, it is userB's sys_id that is printed instead of userA.

 

Why is this?

1 ACCEPTED SOLUTION

I'm not using Before BR because I'm not updating the current object. I am using After BR because I'm updating another record that is related to the current object.

Also, when I checked the sys_journal_fields table, the name under the sys_created_by is userB, not userA. So, that's a thought...

 

Anyway, I moved the target table of my BR to approval table, instead of my custom Task table. This time, userA is now the author of the comment/work_note, which is correct. 

 

Thank you so much for replying to my question.

View solution in original post

6 REPLIES 6

I'm not using Before BR because I'm not updating the current object. I am using After BR because I'm updating another record that is related to the current object.

Also, when I checked the sys_journal_fields table, the name under the sys_created_by is userB, not userA. So, that's a thought...

 

Anyway, I moved the target table of my BR to approval table, instead of my custom Task table. This time, userA is now the author of the comment/work_note, which is correct. 

 

Thank you so much for replying to my question.

@Lhora Alvarez : Please mark my solution as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.