List of sys id in property

preethigovi
Tera Contributor

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

 

var getAllTask = new GlideRecord('sn_hr_core_task');
var offboardingTaskSysId = gs.getProperty('sn_hr_core.offboarding task sys id');

gs.info("preeV11" +offboardingTaskSysId)
getAllTask.addEncodedQuery('template='+ offboardingTaskSysId);
gs.info("Preein")
getAllTask.query();
while (getAllTask.next()) {
    gs.info('PreeD1')
 
Can you please help me to identify where im missing
2 ACCEPTED SOLUTIONS

J Siva
Tera Sage

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

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@preethigovi 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

@Robert H  Thank you for suggestion Robert, i will check this with business team and make something common check to achieve. Thanks again