How to force the sys_created_on time when creating a record

e_wilber
Tera Guru

The below script works with exception to manually forcing the created on date. What I am doing is converting Incidents to Cases by recreating a Case record and transferring all the data over (including the comments and work notes). All the individual pieces are moving over BUT it's taking the current date/time instead of the original one.

On this journal table I am able to double-click in list view to manually set the date to a previous date just fine. In my script, it isn't honoring what I'm telling it to do though. How do I go about setting this field?

var newJrn = new GlideRecord('sys_journal_field');
newJrn.initialize();
newJrn.name = 'sn_customerservice_case';
newJrn.element = 'comments';
newJrn.element_id = cs;
newJrn.sys_created_by = jrn.sys_created_by.toString();
newJrn.sys_created_on = jrn.sys_created_on;
newJrn.value = jrn.value.toString();
var createdJrn = newJrn.insert();

6 REPLIES 6

Can you check field type of  jrn.sys_created_on and let me know if it's Date Time

vkachineni
Kilo Sage
Kilo Sage

Look at the documentation of 

autoSysFields(false);

 

It might help

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022