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 

yes no field map

Everything (update or insert) will be handled via onBefore script

💡 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 ,

Script

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

    // Add your code here
    // if (source.u_entra_rbac) {
    //     target.name = source.u_entra_rbac;
    //    // target.update();
    // }

      var gr = new GlideRecord("sys_user_group");
    gr.addQuery("name", source.u_name);
    gr.query();
    if (gr.next()) {
        gr.name = source.u_entra_rbac;
        gr.description=source.u_description;
        gr.update();
    }
    else{
        // creation logic and role logic
        var grr = new GlideRecord("sys_user_group");
        grr.initialize();
        grr.name=source.u_entra_rbac;
        grr.description=source.u_description;
        grr.insert();
       
    }
    ignore = true;
   

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

 

Hello @Ankur Bawiskar ,
Even if the record is there it created some also it created one empty record as well.
the script seems to be not ok can you please let me know what might be wrong in it?

Regards,

Debasis

@Debasis Pati 

are you sure the incoming name doesn't have any leading or trailing spaces due to which the query might fail

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

    if (source.u_name.nil()) {
        ignore = true;
    } else {
        var gr = new GlideRecord("sys_user_group");
        gr.addQuery("name", source.u_name.trim());
        gr.query();
        if (gr.next()) {
            gr.name = source.u_entra_rbac;
            gr.description = source.u_description;
            gr.update();
        } else {
            // creation logic and role logic
            var grr = new GlideRecord("sys_user_group");
            grr.initialize();
            grr.name = source.u_entra_rbac;
            grr.description = source.u_description;
            grr.insert();

        }
        ignore = true;
    }

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

💡 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

You are correct @Ankur Bawiskar ,
The data contains space but i checked the excel sheet date some values contains space but the values which contain space those records also have space in in instance as well at last but still some duplicate entries are getting created the empty record creation stopped using the above script though