Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

System Property not working in GlideQuery

jiral
Giga Sage

I am getting an issue with the results of the query based on how the System Property is called in the script. Can anyone see why assigning a System Property to a variable or calling it directly from the addQuery returns invalid/null/empty results? See below for the results comparison.

 

Hard-coded Sytem Property in the Query

 

 

var start = new GlideDateTime(gs.beginningOfToday()); 
var end = new GlideDateTime(gs.endOfToday()); 
var SetParent = new GlideRecord('sys_import_set'); 
SetParent.addQuery('sys_created_on','>=',start); 
SetParent.addQuery('sys_created_on','<=',end); SetParent.addQuery('data_source','7a63d14e87459d54a0ff52083cbb3555'); 
SetParent.addQuery('sys_id','!=',ParentSet) 
SetParent.query(); while(SetParent.next())
 { 
gs.print(SetParent.number);
 } 
gs.print(scheduledDataImportSysId);

 

 

*** Script: ISET0535767
*** Script: ISET0535769
*** Script: ISET0535770
*** Script: ISET0535772
*** Script: ISET0535768
*** Script: ISET0535765
*** Script: ISET0535766
*** Script: ISET0535773
*** Script: ISET0535764
*** Script: ISET0535771
*** Script: 97fe047adb8ab55051f8215fd39619d0

 

Substitute System Property variable in the Query

 

 

	var scheduledDataImportSysId = gs.getProperty('sn_hr_core.scheduled_import_set'); 
    var ParentSet = '636e2378dbc4c69051f8215fd396190c';
    var start = new GlideDateTime(gs.beginningOfToday());
    var end = new GlideDateTime(gs.endOfToday());


			var SetParent = new GlideRecord('sys_import_set');
            SetParent.addQuery('sys_created_on','>=',start);
            SetParent.addQuery('sys_created_on','<=',end);            
            SetParent.addQuery('data_source',scheduledDataImportSysId);
            SetParent.addQuery('sys_id','!=',ParentSet)
			SetParent.query();
			while(SetParent.next())
			{
				gs.print(SetParent.number);
			}
            gs.print(scheduledDataImportSysId);

 

 

*** Script: 97fe047adb8ab55051f8215fd39619d0

 

Call the System Property in the Query

 

 

    var ParentSet = '636e2378dbc4c69051f8215fd396190c';
    var start = new GlideDateTime(gs.beginningOfToday());
    var end = new GlideDateTime(gs.endOfToday());


			var SetParent = new GlideRecord('sys_import_set');
            SetParent.addQuery('sys_created_on','>=',start);
            SetParent.addQuery('sys_created_on','<=',end);            
            SetParent.addQuery('data_source',gs.getProperty('sn_hr_core.scheduled_import_set'));
            SetParent.addQuery('sys_id','!=',ParentSet)
			SetParent.query();
			while(SetParent.next())
			{
				gs.print(SetParent.number);
			}
            gs.print(gs.getProperty('sn_hr_core.scheduled_import_set'));

 

 

*** Script: 97fe047adb8ab55051f8215fd39619d0

 

6 REPLIES 6

There is definitely something wrong with the example scripts:

The script Call the System Property in the Query prints the sys_id of the import set, but we would expect the System Property Value instead...

MarkusKraus_0-1706474664030.png

 

 

Re-did the script from scratch and that finally made it work. Don't know what was wrong before but it finally worked.