- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 06:53 AM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 07:16 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 07:13 AM
So I kept reading and working on my script and I figured it out, but I don't understand WHY the change I made works... the changes I made are in bold, and I understand the update() - this updates the record with the changes made. What I'm confused on is the change from while (PwdResetCatItem.next()) to if (PwdResetCatItem.hasNext())???
var PwdResetCatItem = new GlideRecord('sc_cat_item');
PwdResetCatItem.addQuery('name','Password Reset');
PwdResetCatItem.addActiveQuery();
PwdResetCatItem.query();
if (PwdResetCatItem.hasNext()) { // if there is a record in the query
PwdResetCatItem.setValue('active',false);
PwdResetCatItem.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 07:16 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 07:19 AM
So I had it... and then I lost it. I updated my code to your suggestion Robert, and I see this stinkin' active flag is still checked. I am using the sys_id of the record producer.
Thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2016 07:21 AM
Would changing the Run from Once to OnDemand do anything?
I pressed Execute Now twice and now it's working? Am I not giving it enough time?