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?

10 REPLIES 10

Ankur Bawiskar
Tera Patron

@Debasis Pati 

updating a coalesce field is not a good practice because that's the primary identifier for the system to determine if insert/update happens.

-> Don't use any field map

-> in excel have 2 columns, existing group, new group

-> use onBefore transform script

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

    // Add your code here
    var gr = new GlideRecord("sys_user_group");
    gr.addQuery("name", source.u_existing_name);
    gr.query();
    if (gr.next()) {
        gr.name = source.u_updated_name;
        gr.update();
    }
    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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @Ankur Bawiskar ,
If the record is not present then i need to create a record in the group table with the new name also that's why i have used field map and also i have other fields too to map around 3-4 fields also i have roles record also to be created if not present in the sysgroup_has_role table.

@Debasis Pati 

I will still recommend not to use onBefore since you are trying to update coalesce field

in onBefore handle the insert logic along with other fields

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

    // Add your code here
    var gr = new GlideRecord("sys_user_group");
    gr.addQuery("name", source.u_existing_name);
    gr.query();
    if (gr.next()) {
        gr.name = source.u_updated_name;
        gr.update();
    }
	else{
		// creation logic and role logic
	}
	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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

okay so i will remove the filed mappings and coalesce and will update from there on before script itself my understanding is correct right?