set urgency to high if caller is vip

pk16514
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (g_form.isNewRecord()) {
        var callercheck = g_form.getReference('caller_id', vipcallercheck);
		return;
	}
}

function vipcallercheck(callercheck) {
	if (callercheck.vip == 'true') {
		g_form.setValue('urgency', '1');
		alert('Dear VIP Caller, you are setting the urgency to high');
		return;
	}
}

My solution is working fine. But I want to modify the code such that-

1. First it should set the urgency to high then it should send the alert but my code doing it in reverse order
2. If I choose a VIP Caller, then urgency change to high but if I change the caller again to a non-VIP user before submitting the form, I want the urgency value also change back to its default value what it was before.

Anyone please help me to figure this out.

2 ACCEPTED SOLUTIONS

Sunil25
Mega Guru

You can try with below code

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (g_form.isNewRecord()) {
        var callercheck = g_form.getReference('caller_id', vipcallercheck);
        return;
    }
}

function vipcallercheck(callercheck) {
   
    if (callercheck.vip == 'true') {
        g_form.setValue('urgency', '1');
        setTimeout(function() {

            alert('Dear VIP Caller, you are setting the urgency to high');
        }, 2000); //2000 refers to milliseconds and asking screen to wait for 2 secs

        return;
    }
    else{
        g_form.setValue('urgency', '3'); //Sets default value if user is non vip
    }
}
 
Thanks,
Sunil Safare

View solution in original post

Sagar Pagar
Tera Patron

Hi @pk16514,

 

Try this modified client scripts -

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (g_form.isNewRecord()) {
		var callercheck = g_form.getReference('caller_id', vipcallercheck);
		return;
	}

}

function vipcallercheck(callercheck) {
	if (callercheck.vip == 'true') {
		g_form.setValue('urgency', '1');
		alert('Dear VIP Caller, you are setting the urgency to high');
		return;
	}else{
		g_form.setValue('urgency', '3'); // 3 is default value for Urgency
	}
}

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @pk16514 

 

As you accepted the solution but I am thinking is any OOTB way without code. I think Assignment Look up is the also a way to do. Give a try if possible.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************