Inactivate catalog item with a scheduled job script

will_smith
Mega Guru

I have a simple scheduled job script that I want to inactivate a record producer catalog item at a specific time. Below is my script, but the active flag is still checked when I execute it. I have ran this through a background script by adding gs.print statements and it says the flag is flipping to false. Could someone please tell me what I am missing here?

var PwdResetCatItem = new GlideRecord('sc_cat_item');

PwdResetCatItem.addQuery('name','Password Reset');

PwdResetCatItem.addActiveQuery();

PwdResetCatItem.query();

while (PwdResetCatItem.next()) { // if the catalog item is still active, inactivate it

  PwdResetCatItem.setValue('active',false);

}

1 ACCEPTED SOLUTION

If you're just dealing with one Catalog Item, I'd probably not bother with a while statement at all.



var item = new GlideRecord('sc_cat_item');


item.get('<sys_id of Password Reset item>');


item.active = false;


item.update();


View solution in original post

13 REPLIES 13

Uncle Rob
Kilo Patron

Insert line between row 8 and 9



PwdResetCatItem.update();



EDIT:   Beat me by a second!


will_smith
Mega Guru

Now I just have to work out a notification for this change...


will_smith
Mega Guru

When I move this to production, management wants to know it was done.



As a test in my demo environment, I disabled a catalog item with a class of catalog item and that fired off a notification. So, it has something to do with the fact that this is a record producer - which appears to be on a different table.



find_real_file.png


will_smith
Mega Guru

Fixed it!



Changed the table from Catalog Item to Record Producer. I also added a name, so that it only triggers on this particular one.



Thanks again Robert for helping me out on this.