Transform Script to populate Manager Name

Rick Mann
Tera Expert

We are using a CSV file to import user records into our Service-Now instance where we will have a field for Manager Name. However, out AD only contains the Manager's employee number, not the name. I am writing a Transform script that will pull the ManagerEmployeeNumber value from the current user record, then lookup that value in order to populate the Manager Name value. The script does not appear to do anything when I run the transform, but I am able to create a new button in the user record that will correctly populate an individual user record. I have also tried running the transform script using the "onBefore" and "onComplete" values. Any help is appreciated.

Here is the transform script that I have written so far, which does not work:
-----------------------------------------------------------------------------------------------
//This portion of script is from the "Transform Script" script

/**
* For variables go to: http://wiki.service-now.com/index.php?title=Import_Sets_portal
**/

var vFindManager = new GlideRecord("sys_user");
vFindManager.addQuery("employee_number", source.u_manager_number);
vFindManager.query();
if (vFindManager.next())
{
target.manager = vFindManager.sys_id;
}

------------------------------------------------------------------------------------------------



//This portion of script is from the "Lookup Manager" button (which does correctly populate the Manager Name)

------------------------------------------------------------------

//gs.addInfoMessage("Manager " + current.u_manager_number);

var vFindManager = new GlideRecord("sys_user");
vFindManager.addQuery("employee_number", current.u_manager_number);
vFindManager.query();
if (vFindManager.next())
{
//gs.addInfoMessage("Lookup number " + vFindManager.employee_number);

current.manager = vFindManager.sys_id;
var sysID = current.update();
}
{
gs.addInfoMessage("Manager not found");
}

5 REPLIES 5

Valor1
Giga Guru

When is your transform script running?
Make sure that 1. you are NOT mapping the manager field, and 2. that you are using an "onBefore" script. Alternatively, you could use an onComplete script to process ALL of the user records, even ones that were "skipped" because of the lack of updates.

In your button, I think this is an issue:
var sysID = current.update();

current.update(); needs to be on a separate line


Thanks for the reply.

Originally we had the transform script set to run usign the "onBefore" value.

I also confirmed that we are not mapping the "manager" field. I also tried using the onComplete value and importing new records, but the script did not appear to execute.

The script we have written for the button functionality works with no issue.


I believe that I have a solution for you that does not involve a script.

-Go to your transform map and click on the "New" button for Field Maps.
-Right-click on the form header and select Personalize->Form Layout
-Add ' Referenced value field name' to the form and click Save.
-Select the applicable source field and 'Manager' for the target field in the user table.
-In the ' Referenced value field name' field, enter the table that you're referring to (in this case, I believe that you're referring to sys_user).
-There is a choice list where you can decide what to do if the user does not yet exist (create/ignore/reject).

Hope this helps!


FYI - the "Referenced value field name" should be a field, not a table.

I had a customer who was importing group members in to sys_user_grmember, however their spreadsheet was only group IDs (sys_user_group.u_intouch_tin) and user IDs (sys_user.user_name). These are the fields used to coalesce when imports are done to the respective tables, however the transform field map doesn't map to those. To fix this, I filled in the Referenced value field name to user_name and u_intouch_tin. Think of it as an "indirect coalesce."