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

Hi Zack,

 

I have added below code which is working fine for L1 escalation

function onSubmit() {
//Type appropriate comment here, and begin script below
var action = g_form.getActionName();
if(action == 'escalate')
g_form.setValue('u_l1_escalated_by', g_user.getUserID());
}

AnkitaGupte_0-1704979192311.png

 

Please guide how can we add L2 and L3 escalation.

 

Hi @Ankita Gupte ,

 

Add below logic in your UI action for other escalations as well

var action = g_form.getActionName();
if(action == 'escalate')

if(g_form.getValue('u_l1_escalated_by') == ""){

g_form.setValue('u_l1_escalated_by', g_user.getUserID());

}

f(g_form.getValue('u_l1_escalated_by') != "" && g_form.getValue('u_l2_escalated_by') == ""  ){

g_form.setValue('u_l2_escalated_by', g_user.getUserID());

}

if(g_form.getValue('u_l1_escalated_by') != "" && g_form.getValue('u_l2_escalated_by') != ""  && g_form.getValue('u_l3_escalated_by') == "" ){

g_form.setValue('u_l3_escalated_by', g_user.getUserID());

}

}

 

Thanks,

Swamy

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!

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita Gupte 

you can multiple if else statements

are you hiding the UI action once all Level escalation is done?

If yes then you should ensure UI action is shown with proper condition

Why are you using onSubmit client script? You can have this code in your UI action code itself

Condition: current.u_l1_escalated_by == '' || current.u_l2_escalated_by == '' || current.u_l3_escalated_by == ''

Client checkbox: True
Onclick: escalateCode()

Script:

function escalateCode(){

	var user = g_user.userID;
	if(g_form.getValue('u_l1_escalated_by'))
		g_form.setValue('u_l1_escalated_by', user);
	else if(g_form.getValue('u_l2_escalated_by'))
		g_form.setValue('u_l2_escalated_by', user);
	else if(g_form.getValue('u_l3_escalated_by'))
		g_form.setValue('u_l3_escalated_by', user);

	g_form.save();

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

UI Action has many conditions based on which escalate function works hence wanted to go with client script.