System Property not working in GlideQuery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 07:38 AM - edited 01-28-2024 07:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 07:44 AM
Hello @jiral
Can you check if business rule or system property is in another scope...??
There might be scope issue...
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 07:47 AM
The BR and System Property are in the same scope. Human Resources : Core
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 07:55 AM
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....??
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 08:24 AM
Yes, it's correct. Here it is: