We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Need help in Transform Script

Admin7267
Kilo Sage

I'm new to CMDB data loading, I was working on data load using excel. 

I see there are few reference fields in excel[Assigned to, Company], but instead of sys_id, the display value of the names are given. 

 

How to convert those update those Assigned to and Company fields? 

3 REPLIES 3

Danish Bhairag2
Tera Sage

Hi @Admin7267 ,

 

You can refer below link where u can achieve this requirement with no scripting

 

https://www.servicenow.com/community/developer-forum/populate-reference-field-using-transform-map-sc...

 

Thanks,

Danish

 

Abhijeet_Pawar
Tera Guru

Hello @Admin7267 ,

use Below script which will resolve your query.

 

 

use onbefore event script
   
    var assignedTo = new GlideRecord('sys_user');
    assignedTo.addQuery('name', source.u_assigned_to); 
    assignedTo.query();
    if (assignedTo.next()) {
        target.u_assigned_to = assignedTo.sys_id; 
    }

    // Get the sys_id for the "Company" field
    var company = new GlideRecord('core_company');
    company.addQuery('name', source.u_company); 
    company.query();
    if (company.next()) {
        target.u_company = company.sys_id; 
    }

 

 

  

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 

Thanks and Regards,
Abhijeet Pawar.

Anand Kumar P
Tera Patron

Hi @Admin7267 ,

 

Refer below link
https://www.servicenow.com/community/developer-forum/transform-script-for-reference-field/m-p/207635...

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand