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:57 PM
The role itself is not created at the same time as the userRole-assignment.
In your log, you are printing details of the role (sys_user_role) record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2025 12:00 AM
Actually, the script seems to only work for users that did not inherit the role from a group. Is it possible to change the sys_created_on field for the inherited role. Is it possible to change the sys_created_on field for the date they were assigned to the group? That would be acceptable as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2025 12:32 AM
There is another table tracking user-group-membership assignments.
sys_user_grmember
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2025 11:57 PM
When I tried for a user that does not have the role inherited, it works. I would like to do this for a user that has inherited the role (inherited is true).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2025 12:15 AM
Tried the same, and I can confirm.
It's not allowed to alter a record that's inherited=true
There must be something going on behind the scenes that prohibits the update.
I can see that the script is executing, but the update-call returns a null, i.e. failed update.