- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2022 10:33 AM
I want to import beneficiary data to the employee document table so I have created a data source and transform map
I have written the Source script for the beneficiay feild (reference field)
answer = (function transformEntry(source) {
// Add your code here
var name = new GlideRecord("sn_hr_core_beneficiary");
name.addQuery("beneficiary_name",source.u_beneficiary_name);
name.addQuery("employee",source.u_employee_name);
name.query();
if(name.next())
{
var id= current.sys_id;
}
return id;
// return the value to be put into the target field
})(source);
When I import the beneficiary data it is not getting imported in the employee document table and getting this Message log : "Reference field value for sn_hr_ef_employee_document.u_beneficiary rejected: undefined"
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 03:06 AM
Hi,
the target field which you are setting is reference to "sn_hr_core_beneficiary" right?
then you need to return that record sysId
Also employee field on "sn_hr_core_beneficiary" is reference to sys_user so you need to dot walk to name since you are getting name in your excel
answer = (function transformEntry(source) {
// Add your code here
var id;
var name = new GlideRecord("sn_hr_core_beneficiary");
name.addQuery("beneficiary_name",source.u_beneficiary_name);
name.addQuery("employee.name",source.u_employee_name);
name.query();
if(name.next())
{
id = name.getUniqueValue();
}
return id;
// return the value to be put into the target field
})(source);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 01:59 AM
Hi ,
Please add name instead of current.
answer = (function transformEntry(source) {
// Add your code here
var id =""
var name = new GlideRecord("sn_hr_core_beneficiary");
name.addQuery("beneficiary_name",source.u_beneficiary_name);
name.addQuery("employee",source.u_employee_name);
name.query();
if(name.next())
{
id= name.sys_id;
}
return id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 02:39 AM
Hi,
Employee Field in sn_hr_core_beneficiary table is reference field to user table. We need to query with the sys_id of user at Line 3.
Add something like below . It should work . Please check.
var id = "";
var id1 = "";
var user = new GlideRecord('sys_user');
user.addQuery('name' , source.u_employee);
user.query();
if(user.next()){
id1 = user.sys_id;
}
var name = new GlideRecord("sn_hr_core_beneficiary");
name.addQuery("beneficiary_name",source.u_beneficiary_name);
name.addQuery("employee",source.u_employee_name); Line 3
name.query();
if(name.next())
{
var id= current.sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 03:06 AM
Hi,
the target field which you are setting is reference to "sn_hr_core_beneficiary" right?
then you need to return that record sysId
Also employee field on "sn_hr_core_beneficiary" is reference to sys_user so you need to dot walk to name since you are getting name in your excel
answer = (function transformEntry(source) {
// Add your code here
var id;
var name = new GlideRecord("sn_hr_core_beneficiary");
name.addQuery("beneficiary_name",source.u_beneficiary_name);
name.addQuery("employee.name",source.u_employee_name);
name.query();
if(name.next())
{
id = name.getUniqueValue();
}
return id;
// return the value to be put into the target field
})(source);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader