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

Sagar Pagar
Tera Patron

Hi @Mubashira,

 

Can you share your complete scripts here? It will helpful to find out the issues.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi Sagar, 
Below is a simple code to pull the system property but when called in script include, it is not bringing correct date data.
 
       var inc_GR = new GlideRecord("incident");
      //inc_GR.addEncodedQuery("contact_type=self-service^reassignment_count>=1^sys_created_on>javascript&colon;gs.dateGenerate('2023-04-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");
             var inc_number = inc_GR.getDisplayValue("number");
             
               //gs.print('Incident Sys_id: ' + inc_sys_id);
 
               gs.info('Incident Number: ' + inc_number);
         }

 

 

Hi @Mubashira,

 

Try this updated scripts.

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 filterQuery = gs.getProperty("Test.Encoded.Query.A.MQ");

		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(filterQuery);
		inc_GR.setLimit(500);
		inc_GR.query();
		while (inc_GR.next()) {

			var inc_sys_id = inc_GR.getUniqueValue();
			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 sys_idIN + sysidArr;
	}

};

 

Call in reports:

javascript&colon; Test_Incorrect_Incident_Assignment_MQ().getTest_Incorrect_Incident_Assignment_MQ();

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi Sagar,

The code below is working correctly when I use the encoded query within the script but not when I get the value by calling system properties.

var Test_MQ = Class.create();
Test_MQ.prototype = {
initialize: function() {},
 
getTest_MQ: function() {
 
var sysidArr = [];
var filterQuery = gs.getProperty("Test.Encoded.Query.A.MQ");
 
var inc_GR = new GlideRecord("incident");
inc_GR.addEncodedQuery("contact_type=self-service^reassignment_count>=1^sys_created_on>javascript&colon;gs.dateGenerate('2023-07-01','23:59:59')");  
//inc_GR.addEncodedQuery(filterQuery);
inc_GR.setLimit(500);
inc_GR.query();
while (inc_GR.next()) {
 
var inc_sys_id = inc_GR.getUniqueValue();
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;
}
 
};