Glide Record not inserting record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2012 11:17 AM
Hey everyone, the below GR is behaving correctly. It should query a table and insert 5 new records. It is only inserting one. Not sure what is stopping it from going through all of them. Here is the code...
Default(); function Default() { var ID = current.sys_id.toString(); var GG = new GlideRecord('u_m2m_time_card'); GG.addQuery('u_system_entry', true); GG.query(); while(GG.next()) { GG.initialize(); GG.u_system_entry = false; GG.u_time_card = ID; GG.insert(); } }
thoughts? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2012 12:46 PM
You are reinitializing GG inside the while loop. This blows away the list of GlideRecords you just got from your query. You must use a different variable:
function Default() {
var GG = new GlideRecord('u_m2m_time_card');
GG.addActiveQuery();
GG.query();
while(GG.next()) {
var new_time_card = new GlideRecord('u_m2m_time_card');
new_time_card.initialize();
new_time_card.u_system_entry = false;
new_time_card.u_time_card = ID;
new_time_card.insert();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2012 02:08 PM
If you drop GG.initialize(); it will set the 2 values to what you want. Then insert a new record with all the other values equal to the record in the query; just like an insert and stay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2012 01:55 PM
Are you sure if your query returns five records.....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2022 12:05 AM
Hi Mikolz,
Is this an "after" business rule? If "before" rule, should be using current.getUniqueValue() instead of current.sys_id.