I am trying to setup an import into HR Profiles from CSV report. Need help with transform map script

Daniel Shock
Kilo Sage

I am trying to setup an import of a csv that contains additional employee information (birthday, hire date, etc - things that don't belong in user record).  I am having trouble getting it to work.  I am trying to coalesce on the user.  The value in the User field is first name and last name - Daniel Shock, for example.  This information is not in the CSV...so I am trying to query the matching employee ID that is in both the user table and the csv.  and then update the other fields.  So far this is not working.  I see two warning in the import log that seem to indicate whats going on.  1 -something about the coalesce value not being present....which I'm sure it is...the field names are correct.  and 2 - the target is not defined in line 6 of the script....

 

any help would be appreciated!! Thanks!find_real_file.png

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use this

answer = (function transformEntry(source) {
var empid = source.u_ï___empid_;
var userid = new GlideRecord('sys_user');
userid.addQuery('u_employee_id', empid);
userid.query();
if(userid.next()){

return userid.sys_id;
    }
    return "";
})(source);

View solution in original post

5 REPLIES 5

bryan_strasburg
Mega Guru

Daniel, I think I see the issue.

There are few places where you script Transform Maps, essentially at the Transform Map level or at the Field Level.  You are working at the Field Level.  When you script at the Transform Map level, you often specify the target field, but when you are scripting at the Field Level the target field is specified in the Field Map definition (the second field down in your right hand column).

So, your script on line six shouldn't say: target.user = userid.sys_id, it should say answer = userid.sys_id;

The coalesce error is probably just because this field was not being returned.

Thank you! But - I made the change and it still doesn't work:

 

var empid = source.u_ï___empid_;
var userid = new GlideRecord('sys_user');
userid.addQuery('u_employee_id', empid);
userid.query();
if(userid.next()){
answer.user = userid.sys_id;
}

 

Unable to resolve target record, coalesce values not present: [Script]

I'm wondering if there is something about importing a csv...comparing the csv to the user table and then trying to import into the HR Profile table....

Yeah, good Abhinay got it for you.

The thing you had to fix was that it wasn't answer.user, it is just answer.

You are putting userid.sys_id into the variable answer.  Then returning it to the field map.  The field map is specifying what column it will go to based on the Target Field value you specified on your form (not in your code).

The code he gave you does the same thing, it just returns the sys_id from the function into the answer variable.

Abhinay Erra
Giga Sage

Use this

answer = (function transformEntry(source) {
var empid = source.u_ï___empid_;
var userid = new GlideRecord('sys_user');
userid.addQuery('u_employee_id', empid);
userid.query();
if(userid.next()){

return userid.sys_id;
    }
    return "";
})(source);