Solved

How to create a function with bot?

  • 13 December 2022
  • 9 replies
  • 117 views

Userlevel 2
Badge +4

Hello-

 

I’m trying to do something fairly simple.  I want to loop through an email folder and use the email body data to string out a URL and some other basic things.

 

Essentially, I have an Input of Email Body Data and need to string out a URL and return it back to the parent bot.  I have this scenario for multiple things…..some more complex than others.  In other programming I would use a Function to do this…

 

Function GetURL (emailBody)

       ‘Do some stuff

        GetURL = myURL

End Function

 

I’m having issues doing this in a loop using emails.  Does anyone have any suggestions.  Here is the basic idea:

 

Email Loop >>>>>>>>>>

         Email1……..etc

 

                   GetURL(Input=Email1Data, Output=URL)

                   GetSSN(Input=URL, Output=SSN)

                   GetTaskType(Input=URL, Output=TaskType)

                   GetPPLSoftFlag(Input=SSN, Output=Yes or No)

                   GetOracleFlag(Input=SSN, Output=Yes or No)

                   GetLegacyFlag(Input=SSN, Output=Yes or No)

                   …...etc.

Go to Next Email>>>>>>>>»

 

Can someone kindly point me in the right direction.  I feel like I am missing something very simple.

 

I feel like the loop is in a Parent Bot and all the other functions listed above are child bots if that makes any sense?

 

icon

Best answer by Raul Jaimes 13 December 2022, 16:21

View original

9 replies

Userlevel 5
Badge +9

Hi @Matt 7768 ,

It isn’t clear what is the solution you are searching. For looping a email, you can use Loop action for each email.

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-email-action-loop.html

 

And then, use a dictionary with the data from email message.

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-using-email-properties.html

 

When you can able to get the emailMessage key, perform some strings operations to split, find, or extract the data you need.

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-extract-text-action.html

 

HTH

Regards

Userlevel 7
Badge +13

Hi @Matt 7768 ,

 

Dictionary variable will be using to save the output while looping through emails. You can use the emailMessage key of the dictionary variable to get the email content. You can find the remaining keys and their function in the below link.

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-using-email-properties.html

 

Keep in mind that, by default the BOT will loop inside your Inbox folder and the processing time will be depends upon the number mails inside that folder. That is, if it is high then the processing and execution time also will be high.

For a better practice, loop through subfolder where the number of emails is lesser will be a good option. So, add a rule in outlook to move all desired mails to a subfolder and later loop inside that folder.

 

Userlevel 2
Badge +4

@Padmakumar @Raul Jaimes 

 

Hello-

 

Thank you so much for your responses.  I already know how to do the following actions:

  1. Do an email loop through a specific folder
  2. Use email dictionary by assigning the dictionary to a variable (i.e. dicEmailData)
  3. extract text from email dictionary variable for body (i.e. dicEmailData{emailMessage})

 

The issue is that I need to do something like this for example: 

 

Begin Inbox Loop (Imagine 5 emails)

 

Email 1 >>>

 

Child Bot 1: extract text of URL from body of the email  > Navigate to URL > Click X Button > Click Y Button > Extract National ID (SSN) Value > Return me SSN

Child Bot 2: Then Use SSN as an input within the same loop to another bot that checks X Website and then Returns a value

Child Bot 3: Then use SSN as another input  in the same loop to another bot that checks Y Website and then Returns a value

Child Bot 4: Do more stuff here based on the above result….

 

…….Go to Next Email (Email 2) >>»

 

 

I am having trouble passing the emailbody to a bot and return the SSN to my Parent bot and then loop to the next email

 

It appears that only one value is picked up from the child bot… i.e. the last email in the inbox….  I need this to operate like a function in a normal programming language.

 

‘For Example ChildBot 1 looks like this…...

Function GetSSN(emailBody)

       Extract URL from Email Body

       Navigate to URL

       Click X Button

       Click Y Button

       Get SSN Value

       GetSSN = SSN 

End Function

Userlevel 5
Badge +9

Hi @Matt 7768 ,

Declare emailBody as input variable in a child bot. Then, declare SSN like an output variable in the same child bot. Both values should be mapped in the parent bot.

 

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-using-run-action.html

 

Example:

 

sub taskbot to get SSN (child bot)

 

 

Process parent

 

HTH

Regards

 

Userlevel 2
Badge +4

@Raul Jaimes 

 

Thanks so much that was exactly what I was looking for!

 

I have one additional question.  Based on the above interface it appears there is a variable passed even if the value would potentially be null.  Is there a way to circumvent the passing of the variable from one bot to another…. 

 

i.e. If myVar is Null then do not pass it to the other bot?

Userlevel 5
Badge +9

@Raul Jaimes

 

Thanks so much that was exactly what I was looking for!

 

I have one additional question.  Based on the above interface it appears there is a variable passed even if the value would potentially be null.  Is there a way to circumvent the passing of the variable from one bot to another…. 

 

i.e. If myVar is Null then do not pass it to the other bot?

 

Yes it does. You will need set a IF condition and deal with the exception if so.

Userlevel 2
Badge +4

@Raul Jaimes 

 

I don’t see any options in the variable mapping section to avoid passing the variable back to the procedure….. am I just missing something simple?

 

In my  example we have one boolean variable that lets me know if we find a PersonNumber in any of 3 Systems….

 

I have one mainBot that runs 3 subBots (each subBot checks a different system)

 

…. if a Person Number does exist in a system I want to turn the Flag to TRUE…… However, if the flag is FALSE I would not want to pass it back…

 

i.e. Here is the scenario I am trying to avoid...

 

  1. subBot one Finds Person Number turns PersonNumberFlag to TRUE and passes it back to the mainbot

 

  1. subBot two does not find a Person Number and leaves the PersonNumberFlag as FALSE.  At this point I do not want the flag which is TRUE to be changed back to FALSE….

 

i.e. If I find a Person Number in any of the 3 subBots I want the flag to be TRUE.  Therefore I would not want my variable overwritten once it is TRUE…..

Userlevel 5
Badge +9

@Raul Jaimes

 

I don’t see any options in the variable mapping section to avoid passing the variable back to the procedure….. am I just missing something simple?

 

In my  example we have one boolean variable that lets me know if we find a PersonNumber in any of 3 Systems….

 

I have one mainBot that runs 3 subBots (each subBot checks a different system)

 

…. if a Person Number does exist in a system I want to turn the Flag to TRUE…… However, if the flag is FALSE I would not want to pass it back…

 

i.e. Here is the scenario I am trying to avoid...

 

  1. subBot one Finds Person Number turns PersonNumberFlag to TRUE and passes it back to the mainbot

 

  1. subBot two does not find a Person Number and leaves the PersonNumberFlag as FALSE.  At this point I do not want the flag which is TRUE to be changed back to FALSE….

 

i.e. If I find a Person Number in any of the 3 subBots I want the flag to be TRUE.  Therefore I would not want my variable overwritten once it is TRUE…..

 

Maybe creating different variables (PersonNumberFlag1, PersonNumberFlag2 ,etc.)  in  such case can helps to avoid overwrite the original values. However , at the end you will need create more conditions to validate or a structure IF-ELSE IF can be useful.

Userlevel 2
Badge +4

Thanks so much for the response.  I think the way the software is set up creating 3 different variables is the only path forward.

Reply