How do I set the sys_id value in the source script of a field mapping?

sattar3
Tera Contributor

Hello Everyone,

 

I am loading data into a staging table through an inbound payload. One of the staging table fields, serverosi, contains the sys_id of a record from the cmdb_ci_computer table.

During the transform, I need to populate the target table field u_osi_server, which is a reference field to cmdb_ci_computer.

 

My requirement is to use the sys_id stored in the staging table field serverosi and populate the corresponding reference field u_osi_server in the target table.

What is the correct approach to achieve this in a Field Map Source Script or Transform Map? Can a reference field be populated directly using the sys_id value from the source field?

target table name: cmdb_ci_vmware_instance

@Ankur Bawiskar 

Thanks,

Shaik

3 REPLIES 3

Ramkumar Thanga
Mega Sage

@sattar3 Yes. You can populate the reference field u_osi_server on the target table cmdb_ci_vmware_instance directly using the sys_id stored in the staging table field serverosi, provided that the sys_id identifies a valid record in cmdb_ci_computer. A reference field stores the referenced record's sys_id internally. You do not need to query the cmdb_ci_computer table just to resolve the reference if you already have the correct sys_id. Ensure that the reference table (configured on the target dictionary field). ot required if the source value already contains the correct sysId.

@Ramkumar Thanga thanks for the reply.

I tried it, but not working.

Could you please provide the correct source script?

 

Thanks

Ankur Bawiskar
Tera Patron

@sattar3 

use onBefore transform script and set the value

target.u_osi_server = source.u_field;

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

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