The CreatorCon Call for Content is officially open! Get started here.

Field Map - Source Script

ramkutva
Kilo Explorer

I have one of the field as reference in target table.I need to import the values from the excel file,which contains the value of the field.So i used the field map source script to fetch the sys id of it & thereby to set the value in reference field of the target table.The script is working fine when i try in Script Background but its not in Source script of the field Map.Following is the script part:



var impact=source.fieldname;
var imp_ci=new GlideRecord('table name');
imp_ci.addQuery('name',impact);
imp_ci.query();
if(imp_ci.next()){
answer=imp_ci.sys_id;
}

5 REPLIES 5

ShaneBrazeal
Tera Contributor

You don't even need to do a source script on the field map - you can utilize the Referenced value field name field that is displayed when you are transforming to a reference field (see attachment). In your case the value in that field should be


name
.

You can also find more about the "Referenced value field name" field on this wiki article - http://wiki.service-now.com/index.php?title=Creating_New_Transform_Maps#Creating_a_Field_Map


rrataj
Kilo Expert

an ancient topic but I was also looking for a solution on this, 

the issue is that I have in the import table a host name but I do need a sys_id, so I have to mach the host name from import table with the host name on SNOW and insert into the destination table the sys_id .. 

(in this case the external_unique_Id values are not in sync)

the solution is to add the field maps and run a script on the transform map ( not a transform script ) 

find_real_file.png

find_real_file.png

 

(function transformRow(source, target, map, log, isUpdate) {

	var srv=new GlideRecord('cmdb_ci_server');
	srv.addQuery('name',source.u_hostname);
	srv.query();
	if(srv.next()){ // in this case we take just the first match, should be done by Unique_ID 
		target.u_server_sys_id=srv.sys_id;
	}

})(source, target, map, log, action==="update");

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ram,

If you know which column the value belongs to you can directly give in referenced value field name no need for field map script.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur,

 

I am receiving the display value in my source field. How do I set the sys_id value in the target field?