importing data for 2 different tables, 2nd table data should get imported by coping 1st table data

umam7
Tera Contributor

Hi,

 

I would like to get solution for below request.

 

We have excel data to be imported to 2 different tables. 2nd table data should get imported by coping details of 1st table. Also we have unique filed. While we transform, system should check for unique field in 1st table and if this unique field record is available then it should pick that record and insert to the 2nd table along with other details in excel data.

 

I have tried this configuration as below and didn't work. Records are not getting picked from 1st table and inserted to 2nd table.

  • Created import set table
  • Created Transform map for 2 tables
  • Written transform script in 2nd table transform map
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@umam7 

transform map for 2nd table should be with higher order

check this link

Import multiple tables at the same time and create relationship among them 

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

@umam7 

Hope you are doing good.

Did my reply answer your question?

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

Hi Ankur,

 

Yes i have given order for 1st table as 100 and 2nd table as 300. But it didn't work.

umam7
Tera Contributor

I have given the transform script as below,

 

(function transformEntry(source, target, map, log, isUpdate) {

    // Get the unique field value

    var purchaseorderID = source.u_description_of_transaction;

 

    // Look up the corresponding cost_plan record

    var costPlanGr = new GlideRecord('cost_plan');

    costPlanGr.addQuery('u_po_id', purchaseorderID);

    costPlanGr.query();

 

    if (costPlanGr.next()) {

        // Map fields from cost_plan to fm_expense_line

        target.u_po_number = costPlanGr.u_po_id;

        target.cost_plan = costPlanGr.name;

        target.resource_type = costPlanGr.resource_type;

 

        // Map other fields as needed

    }

 

    // Map fields from the source to the target for fm_expense_line

 

    target.u_po_number = source.u_description_of_transaction;

    target.resource_type = source.u_cost_type_description;

    target.process_date = source.u_booking_date;

    target.cost_center = source.u_cost_center;

    target.u_account_type = source.u_account_type;

    target.u_supplier = source.u_name_of_counterparty;

 

    // Map other fields as needed

})();

 

Here 1st table is cost_plan, 2nd table is fm_expense_line and unique field is PO ID

u_po_id in cost_plan

u_po_number in fm_expense_line