Scheduled job to set catalog item inactive

Cirrus
Kilo Sage

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();
}

1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@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 !! 

View solution in original post

4 REPLIES 4

SANDEEP28
Mega Sage

@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 !! 

Thanks Sandeep, Monday morning blues!

OlaN
Giga Sage
Giga Sage

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.

 

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