- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2025 09:31 AM
Hi community,
I have a field u_closed_incident (type: Date/Time) on the Incident table, and I want to populate it using data extracted from one environment and applied in a second environment. In the first environment, I exported incident numbers along with their actual close dates (from activity history), but in the second environment, those records exist without historical activity. I now want to write a fix script that reads a name-value pair (incident number + close date) from a custom table (e.g., incident) and updates the corresponding Incident records by setting u_closed_incident to the given date. What is the recommended approach to implement this using GlideRecord?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2025 03:55 AM - edited ‎07-21-2025 03:57 AM
Hi @DevYadav, if you need fix script, please apply this code:
(function runUpdate() {
var dataMap = {
"INC0000018": "2025-07-05 11:00:00", // apply records that you need to update.
"INC0000027": "2025-07-04 09:30:00",
"INC0000054": "2025-07-03 15:45:00"
};
for (var number in dataMap) {
var gr = new GlideRecord('incident');
gr.addQuery('number', number);
gr.addQuery('state', 2); // must be closed
gr.query();
if (gr.next()) {
var gdt = new GlideDateTime();
gdt.setDisplayValue(dataMap[number]); // treat as local/display time
gr.u_closed_incident = gdt; // replace 'u_closed_incident' by your actual field name
gr.setWorkflow(false);
gr.update();
gs.info('Updated ' + number + ' with ' + gdt.getDisplayValue());
} else {
gs.info('Skipped (not found or not closed): ' + number);
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2025 12:09 AM
Hi @DevYadav. Is there a reason you want to use a fix script? You could use a transform map and there is a field option available for date/time which will take care of it for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2025 03:55 AM - edited ‎07-21-2025 03:57 AM
Hi @DevYadav, if you need fix script, please apply this code:
(function runUpdate() {
var dataMap = {
"INC0000018": "2025-07-05 11:00:00", // apply records that you need to update.
"INC0000027": "2025-07-04 09:30:00",
"INC0000054": "2025-07-03 15:45:00"
};
for (var number in dataMap) {
var gr = new GlideRecord('incident');
gr.addQuery('number', number);
gr.addQuery('state', 2); // must be closed
gr.query();
if (gr.next()) {
var gdt = new GlideDateTime();
gdt.setDisplayValue(dataMap[number]); // treat as local/display time
gr.u_closed_incident = gdt; // replace 'u_closed_incident' by your actual field name
gr.setWorkflow(false);
gr.update();
gs.info('Updated ' + number + ' with ' + gdt.getDisplayValue());
} else {
gs.info('Skipped (not found or not closed): ' + number);
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.