How to add into Update set deleted record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2017 12:53 AM
Hi all,
I know it's possible to force record to update set by the code below:
gr.insert();
var um = new GlideUpdateManager2();
um.saveRecord(gr);
However, how can I put into Update set the flag that the record is deleted?
gr.deleteRecord();
var um = new GlideUpdateManager2();
um.saveRecord(gr); // does not work, because gr is deleted....
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2017 12:22 AM
Hi guys,
I'm sorry but it seems you did not understand my question.
I know how update set works.
What I need is to insert via script a Data record to update set (data records like users, groups, records from custom tables, etc. are not saved into update sets automatically). I don't want to use update_sync attribute for these tables.
I'm able to capture data records in update set with a script like:
gr.insert();
var um = new GlideUpdateManager2();
um.saveRecord(gr);
However, if the record is deleted, I don't know how to add to update set the flag about deletion.
bernyalvarado jaspalsinghchot Do you understand what I mean?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2017 09:19 PM
Hi Peter, indeed. I understand what you mean.
What I was trying to state is that although you can "hack" your way around to make data part of an update set, that's not the best practice neither the intended way of moving data records through instances. A good example of why that's the case is because "deleted records" are not saved. I'm sure there's probably other side effects.
My recommendation will be to move your data by exporting it as xml and then importing it as needed through the different instances.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2019 02:15 PM
Here is a sample background script I created for this purpose.
(function(){
// Set the variable 'table' to the table of the record type you wish to capture the DELETE for.
// Set the variable 'currentSID' to the sys_id of the record you wish to capture a DELETE for.
var table = 'u_asset_routing_rule';
var currentSID = 'a0cdfbdc13f7a3c4d56758222244b0aa';
var current = new GlideRecord(table);
current.get(currentSID);
var um = new GlideUpdateManager2();
um.saveRecord(current);
var setID = gs.getPreference('sys_update_set');
var updateRecord = new GlideRecord('sys_update_xml');
updateRecord.addQuery('update_set', setID);
updateRecord.orderByDesc('sys_created_on');
updateRecord.setLimit(1);
updateRecord.query();
if(updateRecord.next()){
var myStr = updateRecord.payload + '';
myStr = myStr.replace('action="INSERT_OR_UPDATE"','action="DELETE"');
updateRecord.payload = myStr;
updateRecord.action = 'DELETE';
updateRecord.autoSysFields(false);
updateRecord.setWorkflow(false);
updateRecord.update();
//Un-comment this line if you want the script to also delete the record in question, otherwise it will be left to clean up manually.
//current.deleteRecord();
}
})();
As a note, this script should only be used on tables where record changes are not added and removed from update sets automatically, such as user-defined tables or tables where records are considered data and not configuration, such as Stockrooms.