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

@Ankita Gupte 

I would recommend using UI action to have the code rather than having onSubmit

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader