- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 08:25 AM
I have a list of groups that I wanted to update they types of, and since the field type of lists can't be edited from List View, I put together a quick background script to update them all for me.
var gr = new GlideRecord('sys_user_group');
gr.query();
gs.log("!!!!!!!!!!!ROW COUNT: " + gr.getRowCount() + "!!!!!!!!!!");
while (gr.next()) {
gr.type = '74af88c6c611227d0066386e74dc853d,e906721d4f1b9200c9f4fd511310c790,5fe5721d4f1b9200c9f4fd511310c764,faf5721d4f1b9200c9f4fd511310c78f';
//gr.update();
gs.log(gr.name.toString());
}
The above code worked well. It returned a full list of groups by name. However, when I un-commented like 7 to actually have the groups updated with the list of types (line 6), it stops prematurely. It doesn't appear to "break", and the records it is able to get through get updated as desired. I put the list count at the top to confirm that it is still getting the whole list of groups, and it Confirms that the GlideRecord IS querying all 76 groups. (The one strange thing I noticed is that when it isn't working, the second to last return is blank).
[0:00:00.182] Script completed in scope global: script
*** Script: !!!!!!!!!!!ROW COUNT: 76!!!!!!!!!!
*** Script: L3 Technology Support Center
*** Script: L3 Infrastructure Engineering
*** Script: L3 Identity Management
*** Script: L3 Service Delivery and Program Management
*** Script: L3 ESI Process Management
*** Script: L3 Multimedia
*** Script: L3 ES Mobility
*** Script: ServiceNow Admin
*** Script:
*** Script: zIT Managers
Any idea why it keeps stopping? or how I can possibly put some error catching in my code?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 08:55 AM
This smells like a bug. I'd call for support on this. The script I wrote has some debugging in it to help determine what's going on. If you watch what happens to the sys_id, it fails on a null value (which is where the blank entry second to the end is coming around), then updates the record and stops - like it jumped to the end of the list of records. If you run it again, it gets one more record further each time and does the same thing. If you ran your script 74 times, it would eventually push through, but that's silly.
var gr = new GlideRecord('sys_user_group');
gr.query();
gs.log("!!!!!!!!!!!ROW COUNT: " + gr.getRowCount() + "!!!!!!!!!!");
while (gr.next()) {
gs.log('10: sys_id=' + gr.getValue('sys_id'));
gr.type = 74af88c6c611227d0066386e74dc853d,e906721d4f1b9200c9f4fd511310c790,5fe5721d4f1b9200c9f4fd511310c764,faf5721d4f1b9200c9f4fd511310c78f';
gs.log('20: sys_id=' + gr.getValue('sys_id'));
gs.log('update id=' + gr.update());
gs.log(gr.name.toString() + ' sys_id=' + gr.getValue('sys_id'));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 08:31 AM
I've confirmed mine does something similar with 24 groups and stops after two (with a noted blank entry also.) Something is staring me in the face and I'm not seeing it (yet).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 08:38 AM
I found it has something to do with the Type field (glide_list). I can set other fields like active=true and it's fine. Still working...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 08:42 AM
This seems unfortunate because that is the whole reason I did it ...the other fields I can update from List View

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 08:55 AM
This smells like a bug. I'd call for support on this. The script I wrote has some debugging in it to help determine what's going on. If you watch what happens to the sys_id, it fails on a null value (which is where the blank entry second to the end is coming around), then updates the record and stops - like it jumped to the end of the list of records. If you run it again, it gets one more record further each time and does the same thing. If you ran your script 74 times, it would eventually push through, but that's silly.
var gr = new GlideRecord('sys_user_group');
gr.query();
gs.log("!!!!!!!!!!!ROW COUNT: " + gr.getRowCount() + "!!!!!!!!!!");
while (gr.next()) {
gs.log('10: sys_id=' + gr.getValue('sys_id'));
gr.type = 74af88c6c611227d0066386e74dc853d,e906721d4f1b9200c9f4fd511310c790,5fe5721d4f1b9200c9f4fd511310c764,faf5721d4f1b9200c9f4fd511310c78f';
gs.log('20: sys_id=' + gr.getValue('sys_id'));
gs.log('update id=' + gr.update());
gs.log(gr.name.toString() + ' sys_id=' + gr.getValue('sys_id'));
}