- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:32 AM
Hi all,
I need assistance on writing a background script to move all text from one field to another. I have a requirement to update all records to move the text from short description to description. I could update all 150 records manually or run a background script. Thoughts?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:34 AM
This should be fairly simple. Here you go.
var incRec = new GlideRecord('incident'); //This assumes you are talking about incidents. If not you can change incident to the correct table
incRec.addNotNullQuery('short_description'); //Only update those that have a value in short description
incRec.query();
while(incRec.next()) {
incRec.description = incRec.short_description;
//incRec.short_description = ''; //Uncomment if you want the short description blanked
incRec.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:34 AM
This should be fairly simple. Here you go.
var incRec = new GlideRecord('incident'); //This assumes you are talking about incidents. If not you can change incident to the correct table
incRec.addNotNullQuery('short_description'); //Only update those that have a value in short description
incRec.query();
while(incRec.next()) {
incRec.description = incRec.short_description;
//incRec.short_description = ''; //Uncomment if you want the short description blanked
incRec.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:34 AM
A background script would be quite easy. I recommend putting this in a scheduled job or fix script so you can test it in dev and move it to production.
Standard disclaimer: The following code is untested, requires review and potential modifications.
(function () {
var rec = new GlideRecord('tablename');
rec.addQuery('field', value); // optional filter to get just the record syou want
rec.query();
while (rec.next()) {
rec.description = rec.getValue('short_description');
rec.update();
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:41 AM
Hi,
You should also consider if you want the updates to run business rules and update the timestamps.
"setWorkflow" and "autoSysFields" methods can prevent that.
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:42 AM
You can use below script if you want to update all the records in the Table.
But if you have more than record in the table but you want only 150 to be updated the you need to add one more addQuery with specific condition.
var gr = new GlideRecord("<Table Name>);
gr.addQuery("sys_id", '!=', '');
gr.query();
while(gr.next()) {
if(gr.short_description != '');
gr.description = gr.short_description;
gr.update();
}
Thanks,
Arindam