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

AnveshKumar M
Tera Sage
Tera Sage

Hi @Lhora Alvarez 

Is it possible to share the screenshot of the script, to understand it better?

Thanks,
Anvesh

Hi @AnveshKumar M 
Here is the script of my business rule.

LhoraAlvarez_0-1703116003677.png

When updating the work_notes for the record, the one who triggered it is userA; so userA should be the author. Instead, the displayed author is userB.

@Lhora Alvarez : In your script, you are capturing the logged-in user in the "myUserId" variable, but nowhere in the script are you using the value to display, and I see that you are getting it from the "Opened By" from the case record. Could you change it to myUserId and check it out?

 

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

 

@Lhora Alvarez Author means, user name in the comment body or  comment author?

If it is comment body, you are not referring to current logged in user, even myUserID you have captured at the start of the script.

 

And moreover do not use current.update(), move this code to Before BR and remove the current.update() line.

 

If still you are getting a different user let me know.

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh