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
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Aman Kumar S
Kilo Patron

Hi @Priya

Declare variable outside if:

 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= current.sys_id;  
        }    
return id; 

 

Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

So, Now I have declared the Id out side If:

The Requirement is to insert the beneficiary data but it is getting ignored.

find_real_file.png

You have to share details about the transform map, which is going to be a completely different thing.

Go to your import set and check Import set rows related list to check why the records were ignored

If I have answered your original query, mark the answer as helpful and correct

Best Regards
Aman Kumar

I have checked the import set rows comment it showing NO field values changed and the beneficiary name is not getting updated in employee document table

find_real_file.png