how to check condition in Transform map script

Akki1
Tera Contributor

Hi,

I have excel file which contains two column sys_id1 & sys_id2

Now I am importing records in u_m2m_table where i have two fields field1 and field2. These two fields are references to table 1 and table 2 respectively. Now while importing records in  u_m2m_table I want to check if sys_id1 and sys_id2 are valid and then insert else ignore.

Also I want to insert only if sys_id1 & sys_id2 these both fields are not empty.

I know to use onBefore scripts. But how can it be done? What to write the content?can anyone help with this?

14 REPLIES 14

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

As I had mentioned earlier please do the below, also you should avoid creating duplicate post it is not a good practice.

 

1) Create two field maps for the two fields with coalesce as true and choice action as ignore.

 

Saurav11_0-1667981075199.png

 

Then create a onbefore transform script with the below code:-

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

if(source.fieldname1==''||source.fieldname2=='')
{
ignore=true;
}

})(source, map, log, target);

 

Please mark my answer as correct based on Impact.

Hello,

 

If my answer helped you can you also mark it as correct.

 

Thanks.

Akki1
Tera Contributor

@Saurav11 

Hi, I use your script for if any field is empty

I discovered a bug suppose in the excel

    table1_sysidtable2_sysid
a1221bdgw6svdihsdf12fjdcdvd89bvnsdf9b 
 12fjdcdvd89bvnsdf9b 

 

If one of field is empty and it is not in 1st row it will create record with one of field as empty but if it is in 1st row then it will ignore

Hello,

 

onbefore will run before every row transform so it should be able to handle the empty field on any row