Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Source Script in Tansform mapping

Priya14
Tera Contributor

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"

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Swathi P
Kilo Sage

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; 

Swathi P
Kilo Sage

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;
            
        }    

Ankur Bawiskar
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader