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

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

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

@preethigovi 

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.

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

Robert H
Mega Sage

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