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.

Transform Map Script to get the Name of field of reference field

Shubham Bongulw
Giga Guru

Hi Community,

 

I got the data from client were they have provided the reference of other field of the table. For example-

I have reference field as Asset which is referring to the name field of Asset Table. There is one field called serial number of which client has provided the data in sheet. I tried mapping and tried transform map script as well using gliderecord as below-

var gr= new GlideRecord('x_asset'); //x_asset is asset table name
gr.addEncodedQuery('serial_no='+source.serial_no.); //serial_no is serial number field in asset table
gr.query();
if(gr.next())
{
target.asset = gr.name;   
target.update();
}

Note source field is also mapped to target field

 

Can someone please help me what i am missing?

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @Shubham Bongulw,

Are you updating asset reference field? try by replacing the line


target.asset = gr.getUniqueValue();

 

Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi @Shubham Bongulw,

Are you updating asset reference field? try by replacing the line


target.asset = gr.getUniqueValue();

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Yes Sagar I am trying to update reference field. Let me try your solution.

Thankyou Sagar it worked.

Ankur Bawiskar
Tera Patron

@Shubham Bongulw 

you should set the sysId of the record.

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