Can i update sys_created_on field value

shaik_irfan
Tera Guru

Hi,

 

By any chance if i want to update the created on date how can i do that

 

I tried with below background script but it is not updating

 

 

var usr = new GlideRecord('sys_user');

usr.get("SYSID");

usr.query();

usr.sys_created_on = '2020-01-01';

usr.update();

 

When i see the background it is displaying as sys_trigger insert but when i see the user record it is not updateing

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Shaik,

The sys_created_on field is a GlideDateTime field. Please use the below script:

 

var gdt = new GlideDateTime('2020-01-01 07:00:00');

var gr = new GlideRecord("sys_user");

gr.addQuery('sys_id', '1234546344354543543');

gr.query();

if (gr.next()){

gr.sys_created_on = gdt;

gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on

gr.setWorkflow(false); // Do not run any other business rules

gr.update();

}

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hi Shaik,

The sys_created_on field is a GlideDateTime field. Please use the below script:

 

var gdt = new GlideDateTime('2020-01-01 07:00:00');

var gr = new GlideRecord("sys_user");

gr.addQuery('sys_id', '1234546344354543543');

gr.query();

if (gr.next()){

gr.sys_created_on = gdt;

gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on

gr.setWorkflow(false); // Do not run any other business rules

gr.update();

}

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shaik,

Would like to know the purpose for changing the value to some other value

also sys_created_on is date/time so you need to set the date/time and not only date

var usr = new GlideRecord('sys_user');

usr.get("SYSID");

usr.sys_created_on = new GlideDateTime('2020-01-01');

usr.update();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Priyanka Chandr
Mega Guru

Hi,

try this with the proper value of sys_created_on field:

var dt = new GlideDateTime('2020-04-07 07:00:00');

var gr = new GlideRecord("sys_user");

gr.addQuery('sys_id', '234156784323');

gr.setLimit(1);

gr.query();

if(gr.next())

{

gr.sys_created_on=<new value>;

gr.update();

}

Kindly mark it correct and helpful.

Thanks,

Priyanka