How to remove an item from Mail List(outlook) inside a for each iteration

I have a Mail List which i do a iteration on with for each
inside the for each i have condition where
IF mail.subject.tostring == condition
THEN
I want to remove the item from Mail List
end

can you suggest what to do so i can remove that current item from Mail List

Thanks

Hey @Ahmad_Rais,

You can create one more arrStr[ ] var and store the index of IF mail.subject.tostring == condition one this is complete, have another for each loop for arrStr[ ] and use Invoke Method to remove the item from the MailList.

Thanks,
Sanjit

Hi would you be kind enough to share an example of the sequence ?

thank you

sure I will share it to you.

HI,

We cannot remove item from collection of iteration in ForEAch directly.

So can you try either one of the following?

Use LINQ

listMail = listMail.Where(Function(m) m.Subject<>"Condition").ToList

Create new list and add item which matches your condition in ForEach as the following.

Regards,

Hi yoichi ,
thanks for your answer

i want to remove the item from the mail list so it wont get iteration again

my sequence is like

first FOR EACH on string
second FOR EACH on mail list
need to remove the mail list in here so it dont get inside the iritation again
end second For Each

do something

end FIRST FOR EACH

thannks

Hey @Ahmad_Rais,

PFA the xaml file for reference.
RemoveIndex.xaml (8.8 KB)

Thanks,
Sanjit

Hi,

The following will work if what you want to remove is that subject equals item of string list.

image

Regards,

image

i have this error ,
how do i init it?

Hi yoichi ,
thank you for the reply , but i dont quite get what you mean,

can you please help to share the sequence?

thank you

Hi,

Here you are.

Sample20220905-1.zip (2.6 KB)

Regards,

Hey @Ahmad_Rais,

You can initialize it like

Thanks,
Sanjit

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