- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 09:16 PM
Hi Community,
On incident form, when user selects business service it should show a popup which contains operational status of the business service which user has selected.
Here is my script include.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 12:48 AM - edited 02-26-2024 03:02 AM
Hi @Poorva Bhawsar ,
I found few errors in your script please check below,
1. function Callback corrected to callback
2. You were returning ci.operational_status which will not work you have to get the values from script include and then capture it in answer variable
3.In client script closing flower bracket was in wrong place
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getValue('business_service');
var ga = new GlideAjax('TMUtils');
ga.addParam('sysparm_name', 'getCIStatus');
ga.addParam('sysparm_ci', ci);
ga.getXML(callBack);
}
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//var userData = answer.split(',');
// alert('The status of this Business Application is: ' + answer[0]);
alert('The status of this Business Application is: ' + answer);
}
in script include dont return the object instead return the value which you want
var TMUtils = Class.create();
TMUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIStatus: function() {
var ci = this.getParameter('sysparm_ci');
var gr = new GlideRecord ('cmdb_ci_service');
gr.addQuery('sys_id', ci);
gr.query();
if(gr.next()){
gr.operational_status.getDisplayValue();
}
else{
return '';
}
},
type: 'TMUtils'
});
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 02:49 AM
Hi @Poorva Bhawsar in script include could you please try below,
return gr.operational_status.getDisplayValue();
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 09:42 PM
Hi @Poorva Bhawsar ,
Please refer to the sample codes : https://www.servicenow.com/community/developer-forum/alert-a-dot-walked-field/m-p/1922903
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 10:12 PM
I have already used the getreference function but if use this then it will not show the name of the status it will only show the value. For that i need to use script include and call that script include inside client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 11:33 PM - edited 02-25-2024 11:33 PM
Please use this in alert:
alert('The status of this Business Application is: ' + g_form.getValue('business_service.operational_status'));
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 12:48 AM - edited 02-26-2024 03:02 AM
Hi @Poorva Bhawsar ,
I found few errors in your script please check below,
1. function Callback corrected to callback
2. You were returning ci.operational_status which will not work you have to get the values from script include and then capture it in answer variable
3.In client script closing flower bracket was in wrong place
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ci = g_form.getValue('business_service');
var ga = new GlideAjax('TMUtils');
ga.addParam('sysparm_name', 'getCIStatus');
ga.addParam('sysparm_ci', ci);
ga.getXML(callBack);
}
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
//var userData = answer.split(',');
// alert('The status of this Business Application is: ' + answer[0]);
alert('The status of this Business Application is: ' + answer);
}
in script include dont return the object instead return the value which you want
var TMUtils = Class.create();
TMUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIStatus: function() {
var ci = this.getParameter('sysparm_ci');
var gr = new GlideRecord ('cmdb_ci_service');
gr.addQuery('sys_id', ci);
gr.query();
if(gr.next()){
gr.operational_status.getDisplayValue();
}
else{
return '';
}
},
type: 'TMUtils'
});
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang