Adding group to user after integration is ran

aguanci
Tera Expert

We are getting a full file integration to update User Records and HR Profiles daily, but we run into an issue where we can not add a group to those users. Our goal is to add our 'Contingent Worker' group to each user on the file.

 

We have tried adding a Transform script and a Flow but we can get neither to add the group to the user record. 

 

Flow:

Most of the data coming over is written to the HR Profile so we based the trigger off of this table. 

Table: HR Profile 

Trigger --> EW Position Status = Active & EW Position Entry Date is after Today 

Actions: Create Record on sys_user_grpmember Table 

Fields: Group is Contingent Worker & User is Trigger Record User

 

aguanci_0-1730319753789.png

 

aguanci_0-1730319855176.png

 

 

Transform script:

When: OnAfter

 

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Replace with the actual sys_id of the group you want to add the user to
    var groupSysId = 'fc558e43dbe0cf40afeefdb61d9619cb';

    // Create a GlideRecord object for the group member table
    var gr = new GlideRecord('sys_user_grmember');
    gr.initialize();
    gr.group = groupSysId; // Set the group
    gr.user = current.sys_id; // Set the user to be added

    // Insert the new group member record
    var memberInserted = gr.insert();
   
    if (memberInserted) {
        gs.info('User ' + current.user_name + ' added to group ' + groupSysId);
    } else {
        gs.error('Failed to add user ' + current.user_name + ' to group ' + groupSysId);
    }
   

})(source, map, log, target);
0 REPLIES 0