Help with code

Hello wonderfull people,
Please i need a help regarding this problem:
i have a case where i need to filter some emails having excel attachments and save them. But just the attachement whose names are (“MMM” or “SSS”).
I am using a If activity (inside an for each activity) and the conditions (mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(“MMM”)) or mail.Attachments.Any(Function(x) x.Name.ToLower.Contains(“SSS”)))

However,
the problem is:
if the email has more than one attachment, and one of them respects the string (but not the others ones) , then my robot save not only the attachment that respect the names criterias but also those who are not respecting the name criteria. I need to save just the attachments having “MMM” OR “SSS” as names…

Would you please advice how to make it works.?

thanks in advance

Hi @Ricchch

Since you are converting the Name to ToLower, it’s not recommended to check for the Contains with Caps character. Please try the following query & let us know:

mail.Attachments.Any(Function(x) x.Name.ToLower.Contains("mmm") Or x.Name.ToLower.Contains("sss"))

Hope this helps,
Best Regards.

1 Like

Hello @arjunshenoy and thanks for helping.
Yes , i used lower letters and it show the same problem… Thanks

@Ricchch

On the then side of the code…

I guess you are using save attchments …with no filter

You need to add a filter to save only attachments with these characters…it uses regex to search so use

".*(mmm|sss).*"

Cheers

1 Like

Hello @Anil_G and thanks for helping.
yes , i am using a save attachment activity
After checking if my email has attachment (excel type) i am using a code (shown in the picture below - notepad ).

I’ve never use Regex (and how to do it) . thanks i will check it.

Thanks,

@Ricchch

this filter i gave is to be used int eh save atatchments activity that you have in the then side

just paste the filter expression I gave in the filter attachments property of save attachments

image

cheers

Thanks @Anil_G :slight_smile: :handshake: :clap:

1 Like

Hello @Anil_G
One short question:
The filter here is case sensitive? if yes, is there any way to convert it ToLower …(i mean a syntaxis to make it work not only with capital letters but lower case letters)

i meant instead of using:
“.(mmm|Mmm|MMm|MMM|mMm|mmM).
that is too long and if the string has more than 3 letters it will make longuer too.
Thanks

@Ricchch

I have never tried…but generally this is how we can make case insensitive in regex

"mmm/i" - please check if this works

cheers

Hi @Anil_G
It doesn’t work , thanks anyway
I will try to find it
Thanks :handshake:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.