Best way to show/display info message / alert on form based on change of incident values? (sample script included)

jas101
Tera Expert

Hi guys, what is the best/most effective way of displaying a message on a form to a user based on certain field values (as they change on the form).

Namely we would need a message to appear if the Customer (caller_id) was one of 25 particular customers and a certain Service and Category was selected on the incident form? In actual fact we may need to make it so it's based on a keyword being typed into the short description instead of Service/Category (e.g. 'restore'). Is this possible?

I now include an onChange (field short description) sample script which is working below but I don't think this is very effective in terms of performance currently - how can this be edited to increase incident form performance i.e. ensure it's only doing the minimum look-up necessary.

Many thanks.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading) {
return;
}
var sd = g_form.getValue('short_description');
if (newValue) {
var usr = g_form.getReference('caller_id');
if (usr.u_restore_flag == 'true' && sd.indexOf('restore')!=-1) {
g_form.showFieldMsg('assigned_to', 
'WARNING: This restore must be authorised before assigning for restore', false);
}
else
{
g_form.hideFieldMsg('assigned_to');
}
}
}
7 REPLIES 7

Apurva Malewad1
Kilo Guru

Hi,

can you just elaborate more because what you are saying from this line In actual fact we may need to make it so it's based on a keyword being typed into the short description instead of Service/Category (e.g. 'restore') that I am not getting?

Mark correct/Helpful if it helps you.

 

Regards,

Apurva Malewadikar

Hi Apurva, ideally I need to know how best to display an info message / alert if someone selects a specific customer (1 of 25 users in our system) and then e.g. types 'restore' into the short description field? Thanks.

Hi,

In this case I am not sure but may be you can use business rule by specifying these conditions and then you can use gs.addInfoMessage() to display info message.

 

Please mark Correct/Helpful if it helps you.

 

Thanks,

Apurva Malewadikar

find_real_file.png

Raj68
Mega Guru

Hi djs43,

 

 

You can use 'g_form.modified method to check for changes on the form. 

 

 

 

http://www.servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/

 

 

 

 

 

NOTE: Mark correct or helpful if it helps you.

 

 

Warm Regards,

Raj patel