- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 08:06 AM
Hello Devs,
I've got a Fix Script which only updates the limit amount once, and then when I re-run it nothing updates. Below is the script which partially works or so to say only works once.
(function() {
// Creating a GlideRecord for the 'cmdb_ci' table
var gr = new GlideRecord('cmdb_ci');
// Querying CMDB CI records where 'owned_by' is not empty
gr.addNotNullQuery('owned_by');
// Limiting the query to 10 records
gr.setLimit(10);
// Executing the query
gr.query();
// Looping through the records and updating 'assignment_group' based on 'owned_by'
while (gr.next()) {
gr.assignment_group = gr.owned_by;
gr.update();
}
gs.info('Fix script completed successfully. Updated 10 records.');
})();
Any idea?... Has to be a Fix Script.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 09:58 AM - edited 11-08-2023 09:59 AM
Hi,
Try something like this (worked fine for me).
var copyCmdbResult = copyValues();
if (copyCmdbResult == 0){
gs.info('No records updated');
}
else{
gs.info('Update finished, Updated ' + copyCmdbResult + ' records');
}
function copyValues() {
var cmdbGR = new GlideRecord('cmdb_ci');
cmdbGR.setLimit(3);
cmdbGR.addNotNullQuery('owned_by');
cmdbGR.addNullQuery('assigned_to'); // added to make sure we don't overwrite existing value
cmdbGR.query();
var counter = 0;
while (cmdbGR.next()){
// gs.info('id: ' + cmdbGR.getUniqueValue());
cmdbGR.setValue('assigned_to', cmdbGR.getValue('owned_by')); // used getters and setters
cmdbGR.update();
counter++;
}
return counter;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 09:58 AM - edited 11-08-2023 09:59 AM
Hi,
Try something like this (worked fine for me).
var copyCmdbResult = copyValues();
if (copyCmdbResult == 0){
gs.info('No records updated');
}
else{
gs.info('Update finished, Updated ' + copyCmdbResult + ' records');
}
function copyValues() {
var cmdbGR = new GlideRecord('cmdb_ci');
cmdbGR.setLimit(3);
cmdbGR.addNotNullQuery('owned_by');
cmdbGR.addNullQuery('assigned_to'); // added to make sure we don't overwrite existing value
cmdbGR.query();
var counter = 0;
while (cmdbGR.next()){
// gs.info('id: ' + cmdbGR.getUniqueValue());
cmdbGR.setValue('assigned_to', cmdbGR.getValue('owned_by')); // used getters and setters
cmdbGR.update();
counter++;
}
return counter;
}