- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 12:18 AM
Hi Team,
I declared 30 plus sys id in property as comma separated and wanted to call that in scheduled job.
I need to query HR task table and the pass this sys id in template reference field in HR task and perform some updation.
Its printing the sys ids in log prev11 but not entering the while loop. I guess there is some error in encoded query while i try to pass the list of sys id from property
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 12:29 AM
Hi @preethigovi
Please try the below script.
var offboardingTaskSysId = gs.getProperty('sn_hr_core.offboarding task sys id').toString();
var getAllTask = new GlideRecord('sn_hr_core_task');
gs.info("preeV11" +offboardingTaskSysId)
getAllTask.addEncodedQuery('templateIN'+ offboardingTaskSysId);
gs.info("Preein")
getAllTask.query();
while (getAllTask.next()) {
gs.info('PreeD1');
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 12:40 AM
I assume your system property holds comma separated sysIds and is of type string
update your code as this
Since you are comparing multiple sysIds, you need to use IN operator and not =
getAllTask.addEncodedQuery('templateIN'+ offboardingTaskSysId);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 12:29 AM
Hi @preethigovi
Please try the below script.
var offboardingTaskSysId = gs.getProperty('sn_hr_core.offboarding task sys id').toString();
var getAllTask = new GlideRecord('sn_hr_core_task');
gs.info("preeV11" +offboardingTaskSysId)
getAllTask.addEncodedQuery('templateIN'+ offboardingTaskSysId);
gs.info("Preein")
getAllTask.query();
while (getAllTask.next()) {
gs.info('PreeD1');
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 12:40 AM
I assume your system property holds comma separated sysIds and is of type string
update your code as this
Since you are comparing multiple sysIds, you need to use IN operator and not =
getAllTask.addEncodedQuery('templateIN'+ offboardingTaskSysId);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 01:35 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 02:02 AM
Hello @preethigovi ,
While the solutions provided here will surely make your script work, I need to highlight that putting 30+ sys_ids into a System Property is not a good solution from a maintainability perspective.
As an alternative you could try to identify something that all those HR Templates have in common. For example you could assign them all to the same "Owning group", or add a prefix to their names, e.g. [Offboarding].
Then your script would simply have to query all Tasks with HR Template.Owning group = that group, or HR Template. Name starts with [Offboarding]. No need for that property.
Regards,
Robert