- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2016 08:00 AM
We have a parent table (let's call it "intake") that currently has a UI Action "Copy Intake".
We also have some child tables that contain a reference field back to the parent. Each of these child tables ("Product 1", "Product 2", etc) also has a "Copy" UI Action ("Copy Product 1", "Copy Product 2", etc).
Right now, the child tables do not copy when using "Copy Intake". What we're trying to do is modify the "Copy Intake" UI Action so that the fields from the Intake table AND all the records from the associated child Product tables get copied over.
I think one challenge is, the children know about the parent, but the parent doesn't necessarily know about the children.
Could I query the child tables, create new Glide Records for each of them that contain records, then "while(product.next())" call the corresponding "Copy Product" UI Action from the "Copy Intake" UI Action?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2016 08:13 AM
Yes, you are perfectly on right way of approach -
Could I query the child tables, create new Glide Records for each of them that contain records, then "while(product.next())"
in child tables, the parent record gets accessed by -
var grProd1 = new GlideRecord('Product1');
grProd1.addQuery('u_intake',current.sys_id);
grProd1.query();
while(grProd1.next()){
//here copy all fields except one field
//Intake field because here you have to put the new intake record that got created before
var grNewProd1 = new GlideRecord('Product1');
grNewProd1.initialize();
grNewProd1.u_intake = <newIntake record sys_id>;
//copy all fields from grProd1
grNewProd1.insert();
}
Hopefully it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2016 09:24 AM
I figured out what I was doing wrong. I was assigning the new Sys ID to that reference field but didn't notice I was later assigning that same reference field to the original Sys ID.
I knew it had to be a stupid mistake I was making somewhere...and it was. Thank you again for your help!