- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2021 04:29 PM
I have a simple requirement but for some reason I can't figure out how to do it.
I have two tables, TableA and TableB. I want to update each table with the number of the record created in the other table.
For example:
TableA.short_description = 'some description ' + TableB.number;
TableB.short_description = 'some description ' + TableA.number;
I thought it would be as simple as the example below but TableB's number is not getting updated in TableA's short description.
var a = new GlideRecord('tableA');
a.initialize();
a.short_description = 'something here';
set a bunch of field values
a.insert();
var b = new GlideRecord('tableB');
b.initialize();
b.short_description = 'something here' + ' - ' + a.number;
b.insert();
//Here's where I'm stuck, I'm trying to update the short description on the record just inserted into tableA with the number from the record just created in tableB.
a.short_description = 'something here' + ' - ' + b.number;
a.update();
Can anyone help me out?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2021 04:43 PM
Hi,
As per my understanding I dont think you can do a GideRecord update() after the GlideRecord has been closed with an insert().
So my suggestion is do something like this -
var gr = new GlideRecord("incident");
gr.initialize();
gr.short_description = "This is the first record";
gr.insert();
var yGr = new GlideRecord("problem");
yGr.initialize();
yGr.short_description = "In Problem - "+gr.getValue("short_description");
yGr.insert();
var xGr = new GlideRecord("incident");
xGr.get(gr.sys_id.toString());
xGr.short_description = yGr.number+" ** "+xGr.short_description;
xGr.update();
This is working for me.
Cheers,
Sam
Mark correct/helpful if this helped you 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2021 04:43 PM
Hi,
As per my understanding I dont think you can do a GideRecord update() after the GlideRecord has been closed with an insert().
So my suggestion is do something like this -
var gr = new GlideRecord("incident");
gr.initialize();
gr.short_description = "This is the first record";
gr.insert();
var yGr = new GlideRecord("problem");
yGr.initialize();
yGr.short_description = "In Problem - "+gr.getValue("short_description");
yGr.insert();
var xGr = new GlideRecord("incident");
xGr.get(gr.sys_id.toString());
xGr.short_description = yGr.number+" ** "+xGr.short_description;
xGr.update();
This is working for me.
Cheers,
Sam
Mark correct/helpful if this helped you 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2021 09:28 AM
Thanks Sam, adding the third query to get the record back fixed the issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2021 05:41 PM
Thanks mate, can you please also mark the answer as Correct.
Cheers,
Sam