'Created' field update

_bhishek
Tera Guru

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

3 REPLIES 3

Niklas Peterson
Mega Sage
Mega Sage

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

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.

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