- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 11:19 AM
scenario is i need to find all items related to my parent record and list them out in a script to create a file for them
I am able to create the file fine but the lookup and return of the child records is causing me a headache
this script finds them
var allParts = '';
var rmap = new GlideRecord("u_rma_part_information");
rmap.addQuery("u_rma", current.sys_id);
rmap.addEncodedQuery('ORDERBYsys_created_on');
rmap.query();
while(rmap.next()) {
allParts = rmap.u_rma_part_failed_part_serial + " - " + rmap.u_rma_part_pid + " - " + rmap.u_rma_part_chassis_serial;
gs.log("RMA parts 1 is: " + allParts);
}
// so the gs.log out puts each line found but i want them consolidated so I can spit them out as a single entry below, I've tried allParts[i]; but that fails
var arr = number+ u_rma_ship_to_information+ u_rma_address+ u_rma_city+ u_rma_state+ u_rma_zip+
u_rma_country+ u_rma_ship_to_contact_name+ u_rma_ship_to_contact_phone+ u_rma_ship_to_contact_email+
u_rma_customer_reference+ u_rma_shipping_advice+
allParts ;
any ideas my scripting friends
I need the found records in a string as i need to push them into a file that is being created along with the parent records fields values, the italic fields.
This email script works for an email notification to bring them all back but i can;t appear to get that working for this need:
var gr = new GlideRecord("u_rma_part_information");
gr.addQuery("u_rma", current.sys_id);
gr.addEncodedQuery('ORDERBYsys_created_on');
gr.query();
while(gr.next()) {
template.print("FPN: "+ gr.u_rma_part_failed_part_serial + "<br />" +
"PID: " + gr.u_rma_part_pid + "<br />" +
"CS/N: " + gr.u_rma_part_chassis_serial + "<br />");
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 11:33 AM
Piggy backing off of Allen, here's an example of what your code would look like using an array:
var allParts = [];
var gr = new GlideRecord("table");
gr.addQuery('query');
gr.query();
while(gr.next()) {
allParts.push(gr.my_field); // .push() will add a new item into your array
}
// Finally
gs.log(allParts.toString()); // Comma seperated list of things
Hope this helps,
Dylan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2020 01:57 AM
thanks so much both of you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2020 02:39 PM
Thanks Dylan! FYI In case anyone has same issue as me. I had to add "toString()" to the end of gr.my_field in the while loop, otherwise it was just repeating the same value over and over in the output. Once I added that it worked like a charm. Like this:
var allParts = [];
var gr = new GlideRecord("table");
gr.addQuery('query');
gr.query();
while(gr.next()) {
allParts.push(gr.my_field.toString()); // .push() will add a new item into your array
}
// Finally
gs.log(allParts.toString()); // Comma seperated list of things