- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2014 04:21 AM
I've got a script that is working (thanks to http://www.servicenowguru.com/scripting/client-scripts-scripting/javascript-popup-boxes-servicenow/).
But I want this script to query if the priority field is changing to one of three specific values and then only display.
I can make this happen onSubmit, but would prefer this to be an onChange script so that it's flagged straight away.
Requirement: if the 'priority' field value changes to 6,7 or 8 the alert appears.
--- script ---
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading)
alert('Set the Priority as a Major Incident?');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2014 07:56 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') { //if loading or new value is blank, do nothing
return;
}
if (newValue == 6 || newValue == 7 || newValue == 8){ //if new value is 6,7 or 8
alert('Set the Priority as a Major Incident?');
}
if you wanted to ask the user the question here so they could click OK or Cancel you could use a return confirm and actually set the value if they click OK and mark a major incident field on the form as true
if (confirm('Set the Priority as a Major Incident?')){
g_form.setValue('u_major_incident',true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2014 07:56 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') { //if loading or new value is blank, do nothing
return;
}
if (newValue == 6 || newValue == 7 || newValue == 8){ //if new value is 6,7 or 8
alert('Set the Priority as a Major Incident?');
}
if you wanted to ask the user the question here so they could click OK or Cancel you could use a return confirm and actually set the value if they click OK and mark a major incident field on the form as true
if (confirm('Set the Priority as a Major Incident?')){
g_form.setValue('u_major_incident',true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2014 02:04 AM
Thanks, that did the trick OK and I used the confirm prompt.
One final question on this one, I'd like to add in another query so that if the value changes between 6,7,8 that it doesn't re-apply the template. I'm guessing this would be something like the below but not sure whether this can be a separate query to the newValue query?
if (oldValue != 6 || oldValue != 7 || oldValue != 😎
--- script ---
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') { //if loading or new value is blank, do nothing
return;
}
if (newValue == 6 || newValue == 7 || newValue == 😎 //if new value is 6,7 or 8
if (confirm('Set the Priority as a Major Incident?')){
g_form.setValue('u_major_incident',true);
var grTemplate = new GlideRecord('sys_template');
grTemplate.addQuery('name','* Major Incident Template');
grTemplate.query(templateResponse);
function templateResponse(template) {
if (template.next()) {
applyTemplate(template.sys_id);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2014 02:20 AM
All sorted - thanks all for your help.
For anyone else who may need it the below client script will apply a template to an incident if a value is selected, but will not reapply if changed.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') { //if loading or new value is blank, do nothing
return;
}
if (oldValue == 6 || oldValue == 7 || oldValue == 😎 {
return;
}
if (newValue == 6 || newValue == 7 || newValue == 😎 //if new value is 6,7 or 8
if (confirm('Set the Priority as a Major Incident?')){
g_form.setValue('u_major_incident',true);
var grTemplate = new GlideRecord('sys_template');
grTemplate.addQuery('name','* Major Incident Template');
grTemplate.query(templateResponse);
function templateResponse(template) {
if (template.next()) {
applyTemplate(template.sys_id);
}
}
}
}