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

gs.log("Item active set to " + item.active);



Add that to the line below the update.


Notification not firing... can you look at this Robert?        



find_real_file.png


If you're trying to find out if the script is successful, I'd use logs instead of notifications.



As for your notification, the conditions look ok.   I'd go to the Who Will Receive and make sure you actually have someone specified.   I'd also make sure the "send to event creator" is checked


I'm manually inactivating the item, to get the notification to fire off. The scheduled job is working now, thanks to you.



I've got me ask the User as well as the "Send to event creator" checked, but it's still not firing. Could it have anything to do with it being a record producer and not a standard catalog item? I'm grasping at straws here...


Sure, that's probably one good reason.   But I'm still uncertain why you need the notification at all.