Send the data to Target table based on condition is Transform Map Run Script

cnu1916
Kilo Explorer

HI All,

Could you please help me with below script. My requirement is that in table transform map I do have have one field called "Device type" and the data is for Device type is router, switch, firewall etc. So now my requirement is I would like to Run a script to send only Device type is firewall then the respective data only should be inserted into target table. After that I will map the fields accordingly. Can you please help at earliest.

find_real_file.png

 

Thanks,

Cnu

1 ACCEPTED SOLUTION

Hi,

So if device type is not firewall and not switch then you want to stop insertion?

you should use & condition for this.

if(source.device_type !='Firewall' && source.device_type !='Switch'){
ignore = true;
}

If you use OR then what will happen is when device type is firewall the first condition will evaluate as false and second will evaluate to true and total expression will evaluate to true and hence it will ignore record insertion which you don't want.

same will happen when device type is switch

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So this you should do in onBefore transform script and not in field map.

if(source.<deviceTypeField> != 'firewall'){

ignore = true;

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Rahul Kumar17
Tera Guru

Hi

u can write onBefore transform map script and field map.

write this script

 

if(source.device_type != 'firewall')
{
ignore=true;
}
If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

cnu1916
Kilo Explorer

Hi All, 

Thank you so much for your reply and it is working fine 🙂

I need to add one more condition i.e I would to get the data when the device type is either firewall or switch. I mean I need to write "or " condition in this if condition statement. So I have written like this but it is not working. can you please help on this one.

 

if(source.device_type !='Firewall' || source.device_type !='Switch'){
ignore = true;
}

Thanks,

Cnu

Hi,

So if device type is not firewall and not switch then you want to stop insertion?

you should use & condition for this.

if(source.device_type !='Firewall' && source.device_type !='Switch'){
ignore = true;
}

If you use OR then what will happen is when device type is firewall the first condition will evaluate as false and second will evaluate to true and total expression will evaluate to true and hence it will ignore record insertion which you don't want.

same will happen when device type is switch

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader