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

Vishal Birajdar
Giga Sage

Hello @jiral 

 

Can you check if business rule or system property is in another scope...??

 

There might be scope issue...

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

The BR and System Property are in the same scope. Human Resources : Core

Hmmm.....

 

Is data source value in system property is correct....??

As I see in your hard coded script its 

data_source=7a63d14e87459d54a0ff52083cbb3555;

 

But in below script its different....

Not sure but is it right....??

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Yes, it's correct. Here it is:

jeffiral_0-1706459040519.png