- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 08:13 AM
Hi All!
I was wondering if someone would be possibly able to help me with the following problem:
Description: I am trying to create a client script onChange on incident table that would show an alert based on specific conditions.
Conditions:
1) When on incident CI contains a business department (u_business_departments on cmdb_ci_appl table; this field is a list) of GTT (I would ideally like to use sys ID just to be accurate in case we modify group's name in the future) and priority changes to anything but critical - alert should appear.
2) When on incident priority is anything but critical and CI changes to one that contains GTT as business department.
It is basically two onChange client scripts. The tricky part I cant get right is calling a function that would look for GTT sys ID in list business departments field on cmdb_ci_appl table.
This is what I have so far for this client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var incidentGTT = (newValue != 1 && cmdb_ci_appl_u_business_departments [CONTAINS FUNCTION] 'GTT_sys_id');
if (newValue == incidentGTT) {
alert('alert text');
}
}
I would appreciate any ideas and suggestions!
Kind Regards,
Kamile
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 09:38 AM
Script include Code
-----
var DepartmentAndPrioirty = Class.create();
DepartmentAndPrioirty.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isEligibleDepartment: function(){
var ci=this.getParameter('sysparm_ci');
var kr=new GlideRecord('cmdb_ci_appl');
if(kr.get(ci)){
var deparments=kr.u_business_departments.toString();
if(deparments.indexOf('221f3db5c6112284009f4becd3039cc9')>=0){ // I have hardcoded sys_id. Make sure you change this as you wanted.
return true;
}
}
return false;
},
type: 'DepartmentAndPrioirty'
});
-----
Script Include Screenshot;
Onchange Client Script:
------
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ci=g_form.getValue('cmdb_ci');
var ga = new GlideAjax('DepartmentAndPrioirty');
ga.addParam('sysparm_name','isEligibleDepartment');
ga.addParam('sysparm_ci',ci);
ga.getXML(callBackForAlert);
}
function callBackForAlert(response) {
var priority=g_form.getValue('priority');
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='true' && priority=='1')
alert("Yes alert finally");
}
----
On change Client Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 08:28 AM
Ok,You are almost there. Out of the box cmdb_ci field is created for cmdb_ci table. So you cannot access the fields belongs to specific child table using the getReference of this particular filed.
You need to create client callable script include and use GlideAjax - ServiceNow Wiki. This Script include can be reused in both client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 08:52 AM
Thank you for your suggestion! I have never worked with GlideAjax before, but I will take a look at it Any tips?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 09:38 AM
Script include Code
-----
var DepartmentAndPrioirty = Class.create();
DepartmentAndPrioirty.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isEligibleDepartment: function(){
var ci=this.getParameter('sysparm_ci');
var kr=new GlideRecord('cmdb_ci_appl');
if(kr.get(ci)){
var deparments=kr.u_business_departments.toString();
if(deparments.indexOf('221f3db5c6112284009f4becd3039cc9')>=0){ // I have hardcoded sys_id. Make sure you change this as you wanted.
return true;
}
}
return false;
},
type: 'DepartmentAndPrioirty'
});
-----
Script Include Screenshot;
Onchange Client Script:
------
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ci=g_form.getValue('cmdb_ci');
var ga = new GlideAjax('DepartmentAndPrioirty');
ga.addParam('sysparm_name','isEligibleDepartment');
ga.addParam('sysparm_ci',ci);
ga.getXML(callBackForAlert);
}
function callBackForAlert(response) {
var priority=g_form.getValue('priority');
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer=='true' && priority=='1')
alert("Yes alert finally");
}
----
On change Client Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 08:31 AM
Thank you so much for your help!
I added one more condition though and it stopped working. Would it be possible to add you as a friend and possibly you could take a look at the updated script?
Thank you again,
Kamile