Filter Dictionary Values Dynamically and Get Keys of matches

Hello Dear Forum Visitors,

Please, let me address this question to someone who has already implemented something similar or just know how to approach the following case.
Firstly, I have a dictionary of pairs with sting values inside with such a format {‘email’:‘date’}
Secondly, it’s required that during execution bot runs a background check and verifies if the current date is equal to just any date inside that dictionary.
Lastly, if there’s a valid insertion I am going to have to get its key value, which in my case is an email address.
Interested here in how to update programmatically or with the help of specific activities the dictionary itself.

Very much appreciated,
Yan

I am not sure if i got the question, but i know how to update the Value of a Key:Value Pair.
eg. Lets say Initially i had a Dictionary called Employee > Employee {'Name':'Chandan'}
use Assign Activity > Employee("Name") = "Yan"
result > Employee {'Name':'Yan'}

See if this helps.

1 Like

@ykuzin
some descriptions can be interpretated in multiple directions, but lets try to start with.

lets assume following (the key=emailID, value=a date string)
grafik

now this dictionary should be filtered on the values equals todays date and the emails are to retrieve.

We can do it with a LINQ:
grafik

and will get:
grafik

the date formats can be adopted as by your need. In case of the suggestion is not matching your case, then please provide more detail sample data and a clear description of the expected output. Thanks

Find starter help here:
GetKey_FilterByValue.xaml (5.8 KB)

1 Like

Thank you @ppr for your suggestion to edit opened thread as it looks definitely more descriptive and is just what I was trying to say, I have edited it and will take a note for future topics.

Solution seems to be working fine with predefined array of emails and it looks quite elegant short and clear, although I should do my research on what LINQ actually is. Did you use Vb.net syntax, right?

In my case I’ve got emails coming from different addresses everyday and, considering that I should extract @ address from each letter and pair it with a date it received on, I cannot allow to have array with emails predefined. Therefore I’ve done a little test:

Added assign activity, concatinating new@address.com to your arrEmails. Inside dictData assignment, however, I could not see the new address under debugger.
Is this dictionary just for 3 records?

Hope that it helped shed some light on my case, thank you and please do let me know if there’s something that yet remains unclear.

jus keep in mind that when we setup some solution sample it is done for explanation and showcase purpose. As it was mentioned that there is a dictionary filled up with emailid (as Key) and date (as Value) we assumed that this is your input.

For protoype reasons the dictionary was constructed from Email Array and date generator sequence.

However in case of you need more help to finalize the case just share with us the sample data representing the input to process and the expected output along with a clear description. Thanks

1 Like

Can u reverse it? Just create dictionary with keys (dates as Strings) and values as lists of Strings(emails)?

If yes u could build dictionary of lists of strings (call it dict):

image

Then for each email u are working with u can get date and put it to dictionary. Of course you should check if that date already exist in dictionary as a key. if not, we need to create empty list of string and then add email to it.

So it look like:
image

In above example in invoke method there is only one argument in (string) so that would be email.

After all if you would like to check if there is any emails in that dict with current date it will only need to check if dict.keys.contains(today.toString(“format of date”)) and if so, to get that list of strings (emails) from that key :slight_smile:

2 Likes

Thank you, well basically we’ve got a For Each loop in which email adress and date time is being retrieved out of each letter which get assigned correspondingly to a string format variable after.
Now, with previously declared empty Dictionary and Array how can I fill them in during each iteration, based on what we got from emails?
Hope I’ve explained myself well, however for any clarification, please, do let me know what step is yet not clear.

sorry it didnt cleared as more the details trends to be different from question and description.

For avoiding a heavy ping-pong sequence we can suggest:

  • clear the basics at your end: Adding a value to a dictionary - myDict(myKey) = myValue
  • after populating the dict it can be checked if current date is present and the corresponding emails can be retrieved as described above

in case of remaining questions

  • give a clear input sample data
  • share with us expected output sample data along with description

If you are going to implement my solution just declare empty dict before for each loop. inside that loop place if statement showed above (replace “date” with the variable containing date in string format) and place argument in both invoke with string variable containing email.

After loop is finished you can check your dictionary in if statement dict.keys.contains(current date in string format) and if so in then path you can save value dict(current date in string format) = list_variable

1 Like

Thanks @Yameso I will give it a go and get back. As far as I understand the dictionary you suggested me to create should have date as a key and email as a value first. Then see based on if there’s just any date inside a dictionary, either add an email as a value and it will match key-date using Invoke, or a new list will get created.
I don’t get how you re-assign “new list of strings” to a dictionary. Is by doing so a new date will remain as a key and value will store email addresses? Thanks

You are creating empty dictionary and filling it with data. First case in this loop has to be added as a new date. That why this if activity:

If key date like “2021-03-03” doesnt exist as a key in dict that means there is no lists with emails and we need to create that key and empty list. for this example it would be:

dict(“2021-03-03”) = new list(of String)

and after adding email to list (TargetObject: dict(“2021-03-03”), one argument in: “xyz@mail.com”)

When we hit this date again, there is no new list creation, just adding value.

1 Like

@Yameso Perhaps you could provide a descriptive screenshot of the “dict” variable’ type in your workflow . I’ve encountered some problem with casting while building a workflow. New dict has two parameters, which are 1.of String and the 2.List(of Sting).
What have you got inside variables panel as a complete variable type for “dict” ?
Thank you

This one for dict:

image

1 Like

Hi @Yameso ,
Haven’t you encountered a warning similar to this one that I have for added activity “Invoke Method”. The dict variable has got String as a first parameter and a List of strings for the second parameter.
Here’s the screenshot of the error’s captions and activity’s properties.
Screenshot 2021-03-05 at 11.57.11

In invoke method u need to paste two things:

  1. dict(“String”) (date that need to be key in dictionary)
  2. String (email).

in targetObject u need to put dict(dateExtracted) - im guessing that dateExtracted is String type
in Paramters u need to paste variable (type of string), and thats all:

If you have problems in Assign validation i’m guessing that sth wrong can be with dict variable.
Can you show me what variables do you have in variable panel?

1 Like

Sure, here’s the screenshot:

Screenshot 2021-03-05 at 14.02.19

And by the way,

In invoke method u need to paste two things:

  1. dict(“String”) (date that need to be key in dictionary)
  2. String (email).

it’s cleared out all of the compilers warnings if you could kindly clarify based on what criteria have you decided to pass dict(dateExtracted) as a targetObject and email as a parameter just for my information?
Thank you

Sure. With invoke method you can add item to list. So, target object is dict(dateExtracted) as list, where you need to add item. It has to be written as dict(dateExtracted), because it gives exactly one list, which was saved to dictionary with key value as dateExtracted.

Email as parameter is the item, which should be added.

If you are pleased with this solution please mark my post as one :slight_smile:

1 Like

Of course, by the way is it doable to technically store those dictionary pairs to pile them up with every new run? now I bet on Orchestrator’s assets to do so, or simply writing them to an excel workbook, perhaps there’s some other approach.

I haven’t got better approach. I would probably use csv format instead of excel, cause it is more reliable - it can be even opened in notepad++ when robot is editing csv.

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