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-30-2012 11:36 AM
You are using the same variable to both query records and then insert new ones.
I think this post here is related to another of your posts at Insert items into list upon creation of time card
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2012 11:54 AM
Thanks for the response. I am assuming you are talking about the system_entry field? I also tried the BR without that query condition to see if I could pin point the problem, yet only one record was still being inserted. Even If I use an addActiveQuery, that doesnt seem to work either. And yes, the other post is similiarly related to this. This approach I just tried to cut out the 3 table factor and work with two. Even a bare bones GR like the following inserts one record and stops...
Default();
function Default()
{
var GG = new GlideRecord('u_m2m_time_card');
GG.addActiveQuery();
GG.query();
while(GG.next())
{
GG.initialize();
GG.insert();
}
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2012 12:05 PM
No, you are using the "GG" variable to both query records from "u_m2m_time_card" and then you initialize the same GlideRecord variable, so you are wiping it out and any records you might have returned in the query. If you look at my answer to the other post, it might get you closer to where you want to be.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2012 02:19 PM
Just drop GG.initialize();