Change User Role "sys_created_on" value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 11:27 PM - edited ‎08-04-2025 11:30 PM
Hello,
I'm trying to change for testing purposes the date that a user was given a role. For example, if a user has the role of 'itil', I would like to change the "sys_created_on" value for the role on the sys_user_has_role table to 120 days before today. This is what I have currently (this is done in a PDI). I'm also running this as a background script:
var grUserRole = new GlideRecord('sys_user_has_role');
grUserRole.addQuery('role.name', 'itil'); //Filter to only itil role
grUserRole.addQuery('user.name', 'Chuck Tomasi');
grUserRole.query();
var days = new GlideDateTime();
days.addDaysUTC(-120);
while (grUserRole.next()) {
grUserRole.setValue('sys_created_on', days);
grUserRole.autoSysFields(false); //Allow manual update of sys fields
grUserRole.update();
gs.info('Updated: ' + grUserRole.user.name + ' | Role: ' + grUserRole.role.name + ' | SysCreatedOn: ' + grUserRole.role.sys_created_on);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 11:40 PM
Hi @TerryC03 ,
As this is for testing purpose, can you try adding
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 11:43 PM
is this for a business requirement or for your learning purpose?
script seems fine to me
Did you add log and see what error came?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 11:43 PM
Hi,
In general I would advice not to alter the system generated fields.
If you really want to proceed, then the issue is that the field expects a string, not a GlideDateTime object.
Change one thing and it will work.
// change this line
grUserRole.setValue('sys_created_on', days);
// into this
grUserRole.setValue('sys_created_on', days.getValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 11:51 PM
my gs.info() log is printing:
*** Script: Updated: Chuck Tomasi | Role: itil | Role: 2005-02-19 01:12:11
But it's not showing that on the User Role page.