System property is not working in script include

Mubashira
Tera Contributor

Hi, I am trying to pass the value: contact_type=self-service^reassignment_count>=1^sys_created_on>javascript:gs.dateGenerate('2023-06-21','23:59:59')

and it is not working when called in script include.

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Mubashira ,

 

Since you are calling this script include from a report filter, gs.getProperty() will not work because the script include will be executed on the client side, please try to glide record the system property, try the code below:

 

       var inc_GR = new GlideRecord("incident");
    var propGR = new GlideRecord('sys_properties');
propGR.get('<SYSID of the system property>');
var encodedQuery = propGR.value;
   inc_GR.addEncodedQuery(encodedQuery);
       inc_GR.setLimit(500);
       inc_GR.query();
       while(inc_GR.next()){
   
            var inc_sys_id = inc_GR.getValue("sys_id");
             var inc_number = inc_GR.getDisplayValue("number");
             
               //gs.print('Incident Sys_id: ' + inc_sys_id);
 
               gs.info('Incident Number: ' + inc_number);
         }

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

 

View solution in original post

9 REPLIES 9

Thanks a lot Sagar for all your help.

SANDEEP28
Mega Sage

@Mubashira this is encoded query right?  Could you share your script include code here. I want to see how are you using this in script include. 

I am calling this script include in report

Yes the encoded query which I am declaring in system properties is:

Name: Test.Encoded.Query.A.MQ

contact_type=self-service^reassignment_count>=1^sys_created_on>javascript&colon;gs.dateGenerate('2023-07-21','23:59:59')

And the script include is:

var Test_Incorrect_Incident_Assignment_MQ = Class.create();
Test_Incorrect_Incident_Assignment_MQ.prototype = {
initialize: function() {
}, 
getTest_Incorrect_Incident_Assignment_MQ: function(){
 
       // Objective is to get the incidents for reassignment count > 1 and 'Global Service Desk' is assigned 2 or more times.
          
       var sysidArr = [];
       //var incorrectInc = gs.getProperty('Test.Encoded.Query.A.MQ').toString();
   //var incorrectGSDInc = gs.getProperty('Test.Encoded.Query.B.MQ').toString();
   //var inccount = gs.getProperty('incorrect_inc_limit_smo');
 
       var inc_GR = new GlideRecord("incident");
      //inc_GR.addEncodedQuery("contact_type=self-service^reassignment_count>=1^sys_created_on>javascript&colon;gs.dateGenerate('2023-06-21','23:59:59')");  
   inc_GR.addEncodedQuery(gs.getProperty("Test.Encoded.Query.A.MQ"));
       inc_GR.setLimit(500);
       inc_GR.query();
       while(inc_GR.next()){
   
            var inc_sys_id = inc_GR.getValue("sys_id").toString();
             var inc_number = inc_GR.getDisplayValue("number");
 
sysidArr.push(inc_sys_id);
             
               //gs.print('Incident Sys_id: ' + inc_sys_id);
 
               //gs.info('Incident Number: ' + inc_number);
                       
                                                                
    }
         
 
   return sysidArr;
}
 
};

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Mubashira ,

 

Since you are calling this script include from a report filter, gs.getProperty() will not work because the script include will be executed on the client side, please try to glide record the system property, try the code below:

 

       var inc_GR = new GlideRecord("incident");
    var propGR = new GlideRecord('sys_properties');
propGR.get('<SYSID of the system property>');
var encodedQuery = propGR.value;
   inc_GR.addEncodedQuery(encodedQuery);
       inc_GR.setLimit(500);
       inc_GR.query();
       while(inc_GR.next()){
   
            var inc_sys_id = inc_GR.getValue("sys_id");
             var inc_number = inc_GR.getDisplayValue("number");
             
               //gs.print('Incident Sys_id: ' + inc_sys_id);
 
               gs.info('Incident Number: ' + inc_number);
         }

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

 

Yes!!!! Thanks a lot Karan. Your answer is making my report work.