How to populate reference field using transform map script on the target table?

Ujjwala1
Tera Contributor

Hello Experts,

I have been trying to populate reference field value using transform map script, but it is not giving me exact output.

Could anyone suggest me any changes  in the script so that field will take correct cafe value, Any suggestions much appreciated!

Thank you in advance,

Ujjwala

I am using below script in the run script section 

/**
 * For variables go to: http://wiki.service-now.com/index.php?title=Import_Sets_portal
 **/
var cafe = new GlideRecord('u_tsc_restaurants');
cafe.addQuery('u_tsc_restaurant_number', source.u_store_name);
cafe.query();
if (cafe.next()) {
    var sys_id = cafe.sys_id;

    var gr = new GlideRecord('incident');
    gr.initialize();


    // target.u_tsc_restaurant = source.u_store_name;
    target.short_description = " Test Tickets";
    target.category = "Online";
    target.u_tsc_type = "Menu";
    target.u_tsc_subclassification = "Enable";
    target.assignment_group = " ";
    target.contact_type = "email";
    // gr.insert();

}

I have written field map script also, still it is not working

1 ACCEPTED SOLUTION

Sulabh Garg
Mega Sage
Mega Sage

Hi ujjwala,

Try to write your script as below under run script and it should insert a record in Incident table.

 

var cafe = new GlideRecord('u_tsc_restaurants');
cafe.addQuery('u_tsc_restaurant_number', source.u_store_name);
cafe.query();
if (cafe.next()) {
    var sys_id = cafe.sys_id;   

    var gr = new GlideRecord('incident');
    gr.initialize();

    // target.u_tsc_restaurant = source.u_store_name;

    gr.u_cafe = sys_id;           // If you have reference field of Cafe on Incident table, add this line
    gr.short_description = " Test Tickets";
    gr.category = "Online";
    gr.u_tsc_type = "Menu";
    gr.u_tsc_subclassification = "Enable";
    gr.assignment_group = " ";
    gr.contact_type = "email";
    gr.insert();

}

 

Please Mark āœ… Correct/helpful, if applicable, Thanks!! 
Regards
Sulabh Garg

Please Mark āœ… Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

View solution in original post

1 REPLY 1

Sulabh Garg
Mega Sage
Mega Sage

Hi ujjwala,

Try to write your script as below under run script and it should insert a record in Incident table.

 

var cafe = new GlideRecord('u_tsc_restaurants');
cafe.addQuery('u_tsc_restaurant_number', source.u_store_name);
cafe.query();
if (cafe.next()) {
    var sys_id = cafe.sys_id;   

    var gr = new GlideRecord('incident');
    gr.initialize();

    // target.u_tsc_restaurant = source.u_store_name;

    gr.u_cafe = sys_id;           // If you have reference field of Cafe on Incident table, add this line
    gr.short_description = " Test Tickets";
    gr.category = "Online";
    gr.u_tsc_type = "Menu";
    gr.u_tsc_subclassification = "Enable";
    gr.assignment_group = " ";
    gr.contact_type = "email";
    gr.insert();

}

 

Please Mark āœ… Correct/helpful, if applicable, Thanks!! 
Regards
Sulabh Garg

Please Mark āœ… Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg