How to populate a field based on UI action

Ankita Gupte
Kilo Sage

Hello Experts,

 

We have a UI Action named "Escalate" once a fulfiller click on this field the incident is escalated to next level group. We have a field created referencing to user table named "L1 Escalated By" so who ever is clicking on this Escalate button his name must be populated in "L1 escalated by" field. If second time this is escalated to L2 level then the user name must populate in "L2 escalated by". Is this possible? If yes, how? and if No, then why?

 

Please advice and guide. Thank you.

1 ACCEPTED SOLUTION

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var action = g_form.getActionName();
    if (action == 'escalate') {
        var user = g_user.getUserID();
        var es1 = g_form.getValue('u_l1_escalated_by');
        var es2 = g_form.getValue('u_l2_escalated_by');
        var es3 = g_form.getValue('u_l3_escalated_by');
        if (es1 == "") {
            g_form.setValue('u_l1_escalated_by', user);
        } else if (es1 != "" && es2 == "") {
            g_form.setValue('u_l2_escalated_by', user);
        } else if (es1 != "" && es2 != "" & es3 == "") {
            g_form.setValue('u_l3_escalated_by', user);
        }
    }
}

Here this works!

 

Please mark my solutions helpful, Thank you!

View solution in original post

10 REPLIES 10

Zack Hilacan
Tera Contributor

It's possible. Since UI Action can both be client and server script. There is a function to get the current logged-in which is gs.getUser() then you can do something like 'current.l1_escalated_by=gs.getUser()'. And for the 2nd one just create some conditions similar to this : if field 'l1_escalated_by' is not empty, meaning it has already been escalated once, then put the currently logged in user object to the  'l2_escalated_by' field. (current.l2_escalated_by=gs.getUser()). 

 

Please mark my answer helpful if it addresses your concern as it might help question(s) in relation to this topic.

Thank you!

Swamy Malluri
Tera Guru
Tera Guru

Hi @Ankita Gupte ,

 

You can add logic in "Escalate" UI Action to set current logged user id in "L1 Escalated By" if "L1 Escalated By" is empty. And you can add logic to update "L2 escalated by" with current logged in user if "L1 Escalated By" already have value.

 

Please accept my solution or click helpful button.

 

Regards,

Swamy

Ankita Gupte
Kilo Sage

Hi Zack and Swami,

 

I don't want to do it by UI action. Is there any another way to implement it?

Yes can do Server and client. Server is more complicated so I will suggest in the client side. You can create a onSubmit client script where you're going to get the UI Action's name. And create a condition where if that UI Action has been clicked which is "var action = g_form.getActionName();" then use this value like: 

if(action == 'name of the UI Action' ......)

then you're going to get the Current user's information by 'g_user.getUserID()' then just set the field values like "g_form.setValue('l1_escalated_by',g_user.getUserID())", then do the logic for the 2nd one from my first reply.

 

Please mark it helpful for others reference if they have the same problem. Thanks!