
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 01:52 AM
Morning,
Can anyone advise why this isn't working please. I simply want to set catalog items inactive on a certain date using a scheduled job script:
var rec = newGlideRecord('sc_cat_item');
rec.addEncodedQuery("nameSTARTSWITHItemA^ORnameSTARTSWITHItemB");
rec.query();
while (rec.next()){
rec.active = 'false';
rec.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:03 AM - edited 08-14-2023 02:19 AM
@Cirrus Use below script. There should be space between "new" & "GlideRecord".
var rec = new GlideRecord('sc_cat_item');
rec.addEncodedQuery("nameSTARTSWITHItemA^ORnameSTARTSWITHItemB");
rec.query();
while (rec.next()){
rec.setValue('active', false);
rec.update();
}
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:03 AM - edited 08-14-2023 02:19 AM
@Cirrus Use below script. There should be space between "new" & "GlideRecord".
var rec = new GlideRecord('sc_cat_item');
rec.addEncodedQuery("nameSTARTSWITHItemA^ORnameSTARTSWITHItemB");
rec.query();
while (rec.next()){
rec.setValue('active', false);
rec.update();
}
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 03:02 AM
Thanks Sandeep, Monday morning blues!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 02:14 AM - edited 08-14-2023 02:24 AM
Hi,
This scenario would be an excellent fit to create a Flow, instead of creating a scheduled job.
It would do the same, without the need to write any code.
I highly recommend looking at Flow designer if you haven't already.
As for your code, other than the spacing required after the "new" keyword, the "active" field is a boolean, which would want a TRUE or FALSE value, but you are passing a String value of 'false'
Changing it as follows will probably help:
rec.setValue('active', false);
Had a quick test, just to try it, and I must correct myself, in this case passing a String of "true" or "false" into a boolean value actually works, it interprets the value correctly, so I edited my response.
But in general, you should still try to use setValue() method as my example above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2023 03:05 AM
Ola, thanks for the advice, but I think a scheduled job will work better in this scenario as the action to set inactive needs to sit outside the flow/workflow for each item