Table Transform Map

kack l
Tera Expert

Hello everyone
I have a Table Transform Map requirement
The company name of the imported Excel is the company name. There is a reference type of company name item in the imp set table. I want to change it to the company code when transferring it to the company name item in the target table. The company name item in the target table is a reference type reference to the core commpany table.
How can this be achieved?

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@kack l 

you can use field map script since the target field is referring to company table

Incoming name is company name so didn't understand this part -> want to change it to the company code when transferring it to the company name item

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

The company name of the source table is the string and the target table company name is the reference.
When you want to transfer the company name of the source table to the target table company name, the company name is the company code!
Table Transform Map Run script
(function transformRow(source, target, map, log, isUpdate) {
var companyName = source.u_company_information; 
var companyGR = new GlideRecord('core_company');
companyGR.addQuery('name', companyName);
companyGR.query();
if (companyGR.next()) {
u_company_information field (Reference field) target.u_company_information = companyGR.sys_id; gs.info('Company sys_id set in target table: ' + companyGR.sys_id);
}
else { gs.error('No matching company found for company nameGo3: ' + companyName); } })(source, target, map, log, action === "update");
The result is that the company name is displayed instead of the company code

@kack l 

that's OOB behavior because on Company table "name" field is marked Display=true

If you wish to see Company code then you need to make that field as Display=true but remember this would be a platform change and impact wherever company is used as reference field

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Gurpreet07
Mega Sage

Hi ,

You can also use 'Referenced field value nameto do this without code. In the field mapping for company code to company name , just populate 'Referenced field value name' with the backend name  of company code field from target table.

https://www.servicenow.com/docs/bundle/yokohama-integrate-applications/page/script/server-scripting/...