- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2016 08:10 AM
Hi Team,
I wrote one script include and it contains two functions. How to call these two functions in one reference qualifier.
Please see the below code for the same:
var LoadingTechServicesandBusApps = Class.create();
LoadingTechServicesandBusApps.prototype = {
initialize: function() {
},
loadTechServices: function() {
//gs.log("Inside childServiceRefQual", "ADAM");
var parent = current.u_inc_business_service; gs.log("$$$456 parent "+parent);
var qual = '';
if(parent != '') {
var children = new GlideRecord('cmdb_rel_ci');
children.addQuery('parent', parent);
children.addQuery('child.sys_class_name', 'u_technical_services');
children.query();
qual = 'sys_idIN';
if(children.next()) {
qual += children.child.toString(); gs.log("$$$456 qual1 "+qual);
}
while(children.next()) {
qual += ',' + children.child.toString(); gs.log("$$$456 qual2 "+qual);
}
//Check to see if the parent service has symptoms
/*var symptom = new GlideRecord('u_service_symptom_routing');
symptom.addQuery('u_service', parent);
symptom.query();
if(symptom.hasNext()) {
qual += ',' + parent;
}*/
}
//gs.log('Qual: ' + qual, "ADAM");
return qual;
},
loadBusinessApplications: function() {
//gs.log("Inside childServiceRefQual", "ADAM");
var parent = current.u_inc_business_service; gs.log("$$$456 parent "+parent);
var qual = '';
if(parent != '') {
var children = new GlideRecord('cmdb_rel_ci');
children.addQuery('parent', parent);
children.addQuery('child.sys_class_name', 'u_business_applications');
children.query();
qual = 'sys_idIN';
if(children.next()) {
qual += children.child.toString(); gs.log("$$$456 qual1 "+qual);
}
while(children.next()) {
qual += ',' + children.child.toString(); gs.log("$$$456 qual2 "+qual);
}
//Check to see if the parent service has symptoms
/*var symptom = new GlideRecord('u_service_symptom_routing');
symptom.addQuery('u_service', parent);
symptom.query();
if(symptom.hasNext()) {
qual += ',' + parent;
}*/
}
//gs.log('Qual: ' + qual, "ADAM");
return qual;
},
loadBusinessService: function() {
//gs.log("Inside childServiceRefQual", "ADAM");
var parent = current.u_inc_technical_service; gs.log("$$$7869 parent "+parent);
var qual = '';
if(parent != '') {
var children = new GlideRecord('cmdb_rel_ci');
children.addQuery('parent', parent);
children.addQuery('child.sys_class_name', 'cmdb_ci_service');
children.query();
qual = 'sys_idIN';
if(children.next()) {
qual += children.child.toString(); gs.log("$$$7869 qual1 "+qual);
}
while(children.next()) {
qual += ',' + children.child.toString(); gs.log("$$$7869 qual2 "+qual);
}
//Check to see if the parent service has symptoms
/*var symptom = new GlideRecord('u_service_symptom_routing');
symptom.addQuery('u_service', parent);
symptom.query();
if(symptom.hasNext()) {
qual += ',' + parent;
}*/
}
//gs.log('Qual: ' + qual, "ADAM");
return qual;
},
loadBusinessService1: function() {
//gs.log("Inside childServiceRefQual", "ADAM");
var parent = current.u_inc_business_applications; gs.log("$$$AAA parent "+parent);
var qual = '';
if(parent != '') {
var children = new GlideRecord('cmdb_rel_ci');
children.addQuery('parent', parent);
children.addQuery('child.sys_class_name', 'cmdb_ci_service');
children.query();
qual = 'sys_idIN';
if(children.next()) {
qual += children.child.toString(); gs.log("$$$AAA qual1 "+qual);
}
while(children.next()) {
qual += ',' + children.child.toString(); gs.log("$$$AAA qual2 "+qual);
}
//Check to see if the parent service has symptoms
/*var symptom = new GlideRecord('u_service_symptom_routing');
symptom.addQuery('u_service', parent);
symptom.query();
if(symptom.hasNext()) {
qual += ',' + parent;
}*/
}
//gs.log('Qual: ' + qual, "ADAM");
return qual;
},
};
I need to call the loadBusinessService and loadBusinessService1 in one reference qualifier.
Please help me ASAP.
Thanks & Regards,
Prasanna Kumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2016 11:07 AM
Hi Prasana,
i would suggest you to break down the two function created in your script include into one so check below steps if it makes sense to you.
1. Have only one function.
2. i can see you are pointing two parent value as per the below two function code.
var parent = current.u_inc_technical_service;
var parent = current.u_inc_business_applications;
so you can create a if else condition in the code as per the parent value.
like below
function()
{
if(parent=='a')
{
return a;
}
else if(parent==b)
{
return b;
}
}
above code is just a template and you can try it so based on your parent value your function will work/return value and since you would have single function then you can easily use it in the reference qualifier.
Hope this make a sense.
Regards,
Atul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2016 11:31 AM
Hi Prasananna,
Can you not write a two script include and put the function separately if it is based on the qualification.
Its too late will see tomorrow in case i find something on that , by tomorrow you should have multiple solution since people will give idea starting monday.
Regards,
Atul Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2016 11:06 AM
Hi Prasanna,
To use a javascript function in your RefQual, you will need to choose "Advanced" for the type of reference qualifier to use. Then you can enter javascript in the Reference Qualifier field in this manner:
javascript:var myUtil = new LoadingTechServicesandBusApps();myUtil.loadBusinessService() + myUtil.loadBusinessService1();
If you'd like some examples, go to your Dictionary and setup a filter for Reference qual Contains javascript.
FYI, if you defined each of your functions in an on-demand Script Include instead of using prototype, you wouldn't need the "new" object statement.
(New Feature: On-Demand Functions... )
(Script Includes - ServiceNow Wiki )
Then you could use it just as:
javascript:loadBusinessService() + loadBusinessService1();
Good luck,
-Brian
Edit: BTW, you can enter entire functions in that Reference Qualifier field, you are just limited by the maximum field size. So it's best to define things elsewhere (script includes, BR's, etc.) and just be short and sweet when you call them.