Change User Role "sys_created_on" value

TerryC03
Tera Expert

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);
}
 
When I visit the User Role page for 'itil' under the user Chuck Tomasi, the date doesn't change for the Created On field, under the User Role title at the upper left header of the page. Any help would be appreciated. 
9 REPLIES 9

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.

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.

There is another table tracking user-group-membership assignments.

sys_user_grmember

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).

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.