How to call functions in one reference Qalufier?

prasanna7869
Mega Expert

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

1 ACCEPTED SOLUTION

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



View solution in original post

6 REPLIES 6

Atul Kumar2
Giga Guru

Hi Prasanna,



You can use the below steps.



1. Open the dictionary of the field on which you want reference qualifier.


2. go to the reference specification tab. I believe it will come once you select the advanced option.


3. Select advanced option from the use reference qualifier.



Manipulate your code and function as per the below format and paste it into the reference qal field.



javascript:new ScriptIncludeName().yourFunctionName();



Hope this will help you.



Regards,


Atul Kumar


Yes, Atul Kumar, I followed the same but, I'm unable to use include two functions in one reference Qualifier.



I need to club these two functions and put it in one reference qualifier.



Javascript: new ScriptIncludeName().yourFunctionName1();



Javascript: new ScriptIncludeName().yourFunctionName2();



But, how it is possible.



Please help me same.



Thanks & Regards,


Prasanna Kumar


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



Also, please see the below scenario.


I've three reference fields:


find_real_file.png


If we select one CI from Business Services, based on that CI we should show the CI's in Technical Services and Business Applications (when clicking on magnifier)


Here the parent is Business Services, child's are Technical services and Business Applications.



I fixed this by writing the above script include and I called following functions in reference Qualifiers in Technical Services and Business Applications:



Technical services: javascript:new LoadingTechServicesandBusApps().loadTechServices()


Business Applications: javascript:new LoadingTechServicesandBusApps().loadBusinessApplications()



In the same way,


If we select one CI from Technical Services, based on that CI we should show the CI's in Business Services and Business Applications (when clicking on magnifier)



If we select one CI from Business Applications, based on that CI we should show the CI's in Business Services and Technical Services (when clicking on magnifier).



So, I'm trying to write two different functions for each field and put into one reference qualifier. But, I don't know how to call two functions in one reference qualifier.



So, please provide me the solution for the same.



Thanks & Regards,


Prasanna Kumar