How can I clear just 1 category from Outlook mail

Hi,
My UiPath robot reads emails that are marked with a category (‘DIST_DATA’) and after extracting the attachment, removes this category and changes the category to ‘Processed’. This part is working well.

The issue is, at times, the email could have more than 1 category assigned to it such as ‘DIST_DATA’, ‘NEW Supplier’ or ‘DIST_DATA’, ‘URGENT’
In this case, how can I set the properties in ‘Set Outlook Mail Categories’ such that only the ‘DIST_DATA’ category is removed and the additional category is not removed?

The additional category could be any string and I want to make sure that only the ‘DIST_DATA’ category is removed from a processed email and additional categories are left untouched.

What I have:

image

What I am achieving now:

image

What I would like to achieve:

image

Any recommendations on how I can achieve this?

Thanks!

1 Like

Hey @Deepak_Krishnamurthy

You need to preserve the existing categories by using MailMessage.GetCategories()

  • If the above GrtCategories respond a string with categories you can just do string replace the DistData with Processed

  • If it returns an array then please remove DistData from it and add Processed

Doing these steps as above will make sure all the additional categories are retained and only the dist data is updated

After doing either of the above processing based on the return type of GetCategories method just pass it to the Categories prop of Set Outlook Mail Category

Hope this helps

Thanks
#nK

1 Like

Thanks @Nithinkrishna
Your recommendation worked.

For future reference, I just want to point out how I worked on it based on your idea.

  • Get categories of mail:
    —> this_var = mail.GetCategories.ToArray()

  • Replace string in Array:
    —> this_var = this_var.Select(Function(x) x.Replace(“DIST_DATA”,“Processed”)).ToArray()

Then use this variable “this_var” for ‘Categories’ in the Set Outlook Mail Categories activity.

2 Likes

Cool @Deepak_Krishnamurthy :slightly_smiling_face:

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