Populate/Display the user's name

ElvinSalim
Tera Contributor

When a user has checked the "Follow" checkbox, then displays the user's name in the "Follow by" field. The BR script is not working, do I need other script/logic or just modify it?

 

(function executeRule(current, previous) {
if (current.u_follow == true) {
var user = gs.getUser(); 
current.u_follow_by = gs.getUserDisplayName();
}
})(current, previous);

2 ACCEPTED SOLUTIONS

Harish KM
Kilo Patron
Kilo Patron

you could just do this

current.u_followed_by = gs.getUser().getDisplayName();

Regards
Harish

View solution in original post

Just copy and paste this script and check if it displays the name. I believe it should
One more best practice would be - Transfer the if condition in the "When to run" section of Business rule

(function executeRule(current, previous) {
if (current.u_follow == true) {
        var user = gs.getUserID();
        current.u_follow_by = user;
    }
})(current, previous);

View solution in original post

12 REPLIES 12

I see what's happening here
Every time the form is updating, the BR is executing.
You Should make the BR to work on Insert and not on Update. This will solve your issue

There is a suggestion for the script :- 
Please change line 4, 5 like this :-
var user = gs.getUserID();

current.u_follow_by = user;

@Ashutosh C J 

 

It displays only System Administrator on Insert in BR, so I keep on Update in BR. I added this logic: if user not equal to sysadmin then update it with current user in if statement and it seems to work.

Please move the if condition in "When to Run" section of BR and let it run for Update. For reference, please check the attached screenshot. Then just copy paste this code in script.

(function executeRule(current, previous) {
        var user = gs.getUserID();
        current.u_follow_by = user;
})(current, previous);

AshutoshCJogl_0-1696864164438.png