OnAfter or Field map script transform script help needed

E_19
Giga Expert

Hi All,

Can someone advise on how I should approach the below requirement:

I have load a list of companies into core_company table.

They all have a customer id, debit group id which is often the same but not always

After each load I would like to run an onAfter script to take the debit group id and find the matching name in the core_compnay table

and add this to the reference field Parent.

comp id                                                                                                                                                                                                                                                                                                               Parent field should result in             Debit group id                

100000xyz companystreet 19LondonUKxyz company100000
100001abc Ltdway 1BerlinDEabc Ltd100001
100004time Ltdlane 2 ZürichCHxyz company100000
100005now Ltdroad 3New YorkUSAtime ltd100004

Any suggestions greatly appreciated.

Thanks,

Ellie

16 REPLIES 16

nthumma
Giga Guru

So you want help with script ? can you post exact table names and field names.


yes please I have tried various but struggling with this on



Source table: u_imp_kunden


u_nr_


u_debitoren_gruppencode


u_name



Target table: core_company


u_company_id


u_debitor_group


name


parent   (this is is a reference field to itself i.e. core_company)



Either during import the Parent field is populated with the company as per value in u_debitoren_gruppencode



or after the load we could run a script to populated the Parent field with the company name as per value in u_debitoren_gruppencode



whatever is best



Many Thanks,


Ellie


try this onBefore script.


var gr new GlideRecord('core_company');


  gr.addQuery('u_debitor_group',source.u_debitoren_gruppencode);


  gr.query();     // Issue the query to the database to get all records


  while (gr.next()) {    


        // add code here to process the incident record


              traget.parent = gr.sys_id


  }


Just few changes and additions to above code poposed by @srnewbie




var gr new GlideRecord('core_company');    


  gr.addQuery('u_debitor_group',source.u_debitoren_gruppencode);  


  gr.query();     // Issue the query to the database to get all records  


  while (gr.next()) {        


        // add code here to process the incident record  


              traget.parent = gr.sys_id  


  }


 


  gr.addQuery('u_debitor_group',source.u_debitoren_gruppencode);  


  The above line would be valid if you are getting the sys id of the group but if it is the group id you might have to modify the u_debitor_group.groupID


 


  Also, saw a typo in the above code. It is target.parent