Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Transform Script for LDAP group import

arnoldha
Tera Guru

Hi All,

 

I'm currently importing some groups from my Active Directory. For one group, the name in ServiceNow is different from the sAMAccountName in AD, and it is not possible to change it. I would like both to be synced together, so I write a Transform Script, but somehow it is still not working properly. They are not syncing together and a new group got created on ServiceNow.

 

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

    if (source.u_name == "hallo" ||  source.u_samaccountname == "hallo") {

		target.name = "hello";
    }

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

 

I tried all type of transform script: onBefore or onStart,... does nothing... Any ideas ?

 

Thanks in advance ! 

1 ACCEPTED SOLUTION

Thanks for you answer @SwarnadeepNandy ! I tried you script but I didn't work for me. Actually I changed the Source Field to a script to map with the group name :

 

answer = (function transformEntry(source) {

	// Add your code here
	if (source.u_name == "Hallo" ||  source.u_samaccountname == "Hallo") {

		return "Hello";
    } else {
		return source.u_samaccountname;
	}
    

})(source);

 

View solution in original post

2 REPLIES 2

SwarnadeepNandy
Mega Sage

Hello @arnoldha,

You are just setting the name field for a new record. So, new records are getting created every time.

What you are trying to achieve is to update the existing record. So, to update the existing record you have to change the coalesce (true) record to script.

 

  • Use Source Script = true
  • Source Script = 

 

answer = (function transformEntry(source) {

    // Add your code here
    var gr = new GlideRecord("sys_user_group");
    gr.addEncodedQuery("name=<SERVICENOW_GROUP_NAME>^ORname=<SAMACCOUNTNAME>");
    gr.query();
    if (gr.next()) {
        return gr.sys_id;
    } else {
        return -1;
    }

})(source);​

 

  • Target field = sys_id

 

Sample screenshot

SwarnadeepNandy_1-1693577513000.png

 

Ignore the Map, source Table and Target table values in the screenshot.

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy

Thanks for you answer @SwarnadeepNandy ! I tried you script but I didn't work for me. Actually I changed the Source Field to a script to map with the group name :

 

answer = (function transformEntry(source) {

	// Add your code here
	if (source.u_name == "Hallo" ||  source.u_samaccountname == "Hallo") {

		return "Hello";
    } else {
		return source.u_samaccountname;
	}
    

})(source);