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

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

pk16514
Tera Contributor

Thanks @Sunil25 

Harish Bainsla
Tera Sage
Tera Sage

hi try to write on change client script on change of caller field

var caller = g_form.getReference('caller_id');

var is VIP = caller.getValue('vip');

if(isVIP=='true'){

g_form.setValue('urgency',1);

alert('caller is vip');

}

 

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