'Created' field update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 10:23 AM
Hi All,
I have incorrect 'created' field data for computer CIs.So for all the computer CIs ,For which discovery source is service now ,We want to replace 'Created' field data with 'First discovered' field data for each CIs.
Could you please help me with fix script for this.
Thanks & regards,
Abhisek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 10:48 AM
Hi,
How can you have incorrect data for 'created'?
Created (sys_created_on) is the time stamp when the record was created in the table. It should not be "tampered" with.
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:00 AM
Hi Niklas,
Thanks for your response .
We have a transform map to import CIs,In that transform map ,'created' field is mapped with source 'last discovered date' Which is incorrect mapping .We have fixed that mapping now . But for old data ,We want to replace created field data with 'First discovered' field data for all computer CI,for which discovery source is 'ABC' and 'first discovered date' field is not empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:11 AM
Hi,
OK, I understand. Something like this then.
var glideRecord = new GlideRecord('cmdb_ci_computer');
glideRecord.addQuery('discovery_source', 'servicenow');
glideRecord.addQuery('first_discovered', '!=','');
glideRecord.query();
while (glideRecord.next()) {
glideRecord.setValue('sys_created_on', glideRecord.first_discovered);
glideRecord.update();
}
Please test in non-prod first!
Regards,
Niklas