- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 08:09 AM
I have two custom tables, table a and table b. Once a record is updated on table a I want to move the record to table b and delete it from table a. I should note that this is being run from a business rule.
My approach:
//first gather all of the data i am going to delete
var a = new GlideRecord('tableA');
a.addQuery('number',number); //find the record
a.query();
if (a.next()) {
name = a.getDisplayValue('name');
}
//this works i get the records i want
//now i am going to insert the collected data into table b
var b = new GlideRecord('tableB');
b.initialize();
b.setValue('name', name);
b.insert();
b.update();
//here is where it gets weird when i attempt to delete the old record on table a
var del = new GlideRecord('tableA');
del.addQuery('number',number);
del.query(); //if i leave this line as is the record will not be inserted into table b. however if i comment this line out the record will be inserted but the old record
//wont be deleted from table a.
del.next();
del.deleteRow();
del.update();
Can anyone show me what I am doing wrong?
Thank you in advance.
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 08:19 AM
I'm not sure why you are querying multiple times to delete the same record
here is the updated code..
var a = new GlideRecord('tableA');
a.addQuery('number',number); //find the record
a.query();
if (a.next()) {
var b = new GlideRecord('tableB');
b.initialize();
b.setValue('name', a.getDisplayValue('name'));
b.insert();
a.deleteRecord();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 08:14 AM
GlideRecord - Scoped - check to use deleteRecord() instead of deleteRow()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 08:19 AM
Apologies I am using deleteRecord() not deleteRow()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 08:19 AM
I'm not sure why you are querying multiple times to delete the same record
here is the updated code..
var a = new GlideRecord('tableA');
a.addQuery('number',number); //find the record
a.query();
if (a.next()) {
var b = new GlideRecord('tableB');
b.initialize();
b.setValue('name', a.getDisplayValue('name'));
b.insert();
a.deleteRecord();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 08:54 AM
I tried this and the record on table a doesn't get deleted and the record never gets inserted on table b.