How to set the condition in transform map script before inserting the data in target table

Munna1
Tera Contributor

How can we set condition in transform map, to cross check the user is present in the User table before inserting the data in the target table.

 

I have three tables named u_depatment_table (Source table) and u_employee_table(Target table)  and sys_user table in these tables one field is common, called User field(Reference to sys_user table) whenever records are coming from source table First it hast to cross check that user is present in the User table or Not  -> if it preset Then it has to insert the records in the target table respectively.

I have added few fields in the field mappings and set the User field to Coalesce

And please suggest me , shall I use the Transform Run script or the  On before script.

 I have written this code, but it is not working out. 

 

 

var myUser = new GlideRecord('u_department_table'); // Source Table
myUser.addEncodedQuery('user_nameISNOTEMPTY');
    myUser.query();
    while (myUser.next()) {
        var userAccount = myUser.getValue('user_name');
        var myempUser = new GlideRecord('sys_user'); 
        myempUser.addQuery('user_name', userAccount);
        myempUser.query();
        if (!myempUser.hasNext()) {
var grtarget = new GlideRecord('u_employee_profile'); //target table
 
grtarget.initialize();
 
grtarget.insert();  
        }
else{
ignore = true;
}
    }
2 REPLIES 2

Mark Manders
Mega Patron

Use an onBefore script so it runs before the transform starts. 

What are you doing with your 'initialize'/'insert'. You are creating an empty record this way.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders 

 

Here With the help of User field in Source table, we have to check that user is present or not in the Sys_user table .

If it present then it has to create the records in the target table.

I have added few fields in the field mappings and set the User field to Coalesce

 

If I got the user who is present in sys_user table then what is the next step to do..then...(I got stuck here...)