- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 06:20 AM
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 !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 08:26 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 07:13 AM
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
Ignore the Map, source Table and Target table values in the screenshot.
Hope this helps.
Kind Regards,
Swarnadeep Nandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 08:26 AM
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);
