We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Transform Map issue

Debasis Pati
Kilo Sage

Hello All,
i have a excel sheet data with updatedgroupname and existinggroupname values.
i need to update the data existinggroupname is coelece so that it wont create updated fileds also i have created one on before script to do the name change.

gs.info("test123------"+source.u_updatedgroupname);
    target.name = source.u_updatedgroupname;
  
The issue is group name is not updating.
@Ankur Bawiskar any suggestions?

1 ACCEPTED SOLUTION

@Debasis Pati 

yes it won't work to give security_admin via script.

Not a good practice to give security_admin via script even if it's feasible

security_admin role should be given only by Security admins and it should be a manual activity.

I believe I answered your original and subsequent questions.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

17 REPLIES 17

@Debasis Pati 

you can't make it work unless the data in target table is correct.

it should not have leading or trailing spaces in it.

Run a background script in instance before loading the data and remove leading and trailing spaces from name field of sys_user_group

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@Debasis Pati 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hello @Ankur Bawiskar ,
We need to correct the data in instance using fix script or background script:
I just tried one on after transform map script to create the roles if they are not present but it is not working it seems:

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

    // Add your code here
   
    var groupname = source.u_entra_rbac;
    var grprole =source.u_role;
    // var gr = new GlideRecord('sys_group_has_role');
    // gr.addQuery('group='+target.sys_id+'role.name='+grprole);
    // gr.query();
    // if(!gr.next()){
    //  var grr = new GlideRecord("sys_group_has_role");
    //  grr.initialize();
    //     grr.group=groupname;
    //  grr.role=grprole;
    //  grr.insert();
       
        var grRole = new GlideRecord('sys_group_has_role');
        grRole.addQuery('group.name', groupname);
        grRole.addQuery('role.name', grprole);
        grRole.query();
        if (!grRole.hasNext()) {
            grRole.initialize();
            grRole.setDisplayValue('group',groupname);
            grRole.setDisplayValue('role', grprole);
            grRole.insert();
            log.info('Added role ' + roleName + ' to group ' + target.name);
        }
       
   

   


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



@Debasis Pati 

are you sure you are giving exact group and role name?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Earlier you have suggested to do it on on before only but in on before i have the logic to change the names so thought of creating roles in one on after and tried it .It only created one record only not sure why