Best way to show/display info message / alert on form based on change of incident values? (sample script included)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 02:49 AM
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');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2018 03:41 AM
Hi, thanks. I have updated my question with a working sample script - can this be improved? Thank-you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2018 04:12 AM
Use a GlideAjax call with a script include instead of getReference, it's offers better performance.
Client Script;
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getUserInfo');
ga.addParam('sysparm_user_id', g_user.userID);
ga.getXMLAnswer(callBack);
function callBack(answer) {
var thisAnswer = JSON.parse(answer);
var restore_flag = thisAnswer.restore_flag;
if (restore_flag == 'true')
g_form.showFieldMsg('assigned_to', 'WARNING.....')
else g_form.hideFieldMsg('assigned_to');
}
}
Script Include;
var getUserInfo = Class.create();
getUserInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRestoreFlag : function () {
var thisUser = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('sys_user');
gr.get(thisUser);
var restore_flag = {
restore_flag : gr.getValue('u_restore_flag') + ''
};
return new JSON().encode(restore_flag);
},
type: 'getUserInfo '
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 03:28 AM
Many thanks for this and sorry for the delay.
Please can you tell me, is the intention with your client script that it would be onChange of the 'Customer' (i.e. 'caller_id') field? I can't see any reference to this so am a little confused.
As per my original sample script is there a way to factor the Short description into this also e.g. in my script I had the line:
sd.indexOf('restore')!=-1
(sd being Short description).
Thanks again!