Download Only ".xlsx" file or Throw exception

I am looking for a mail which will be receiving multiple file formats, but I want to specifically download only the (.xlsx) file. If no (.xlsx) file is found in the attachment it should throw a business exception. I have set the filter type to .xlsx in save attachment but not getting how to add the conditions because, in the first “IF” condition, I am checking with the subject of the mail to download the file.

There are 3 conditions to be considered

  1. If the mail is blank / Or has no Attachments
  2. if there is no file with (.xlsx)
  3. if the downloaded Excel has no data in it.

Thanks in Advance

Hey @Anirudh_Tugawe ,

Check the below thread

Hope it helps u

1 Like

@Anirudh_Tugawe

You can give condition like this for 1 and 2

Mailvariable.Attachments.Count>0 andAlso MailVariable.Attachments.Where(function(x) x.Name.ToLower.Contains(.xlsx)).Count>0

If the above condition is true that is on then side save the attachment usign save attachments with filter…and then read the attachment and check the rowcount>0 for 3rd codnition

Cheers

1 Like

Hi @Anirudh_Tugawe

You can try the below syntax:

If
 String.IsNullOrEmpty(mail.Subject) OrElse mail.Attachments.Count = 0 OrElse
                   Not mail.Attachments.Any(Function(attachment) attachment.Name.EndsWith(".xlsx"))
Then
     Throw New BusinessRuleException("yourmessage")
Else
     -> Use Save Attachments acitivity to save the excel
     -> Read Range Workbook          Output-> dt_datatable
        If
           dt_datatable.Rows.Count=0
       Then
            Throw New BusinessRuleException("exceptionMessage")
        Else
           \\ Do required process
        End If
End If

After saving attachments in the then section use read Range Workbook to read the excel and after that use an if condition yourdatatable.Rows.Count=0.

Reards

1 Like

Hello, you there? I just needed a quick help here!!

I am working on automation where I am required to take only 10 digits from the variable, in case someone types and updates the data eg. the IDno is “7276176684shaenjk” so it should take only 10 digits not the other char nor the number except this.

and one more requirment is there is tab where i can enter only the int if we enter string by mistake then it should throw the BE, but here i am tring to add the if activity so the required / filtered data only will get uploaded.

can you help me with this scenario?

Hello, you there? I just needed a quick help here!!

I am working on automation where I am required to take only 10 digits from the variable, in case someone types and updates the data eg. The “IDno” is “7276176684shaenjk” so it should take only 10 digits, not the other char nor the number except this.

and one more requirement is there is a tab where I can enter only the int if we enter a string by mistake then it should throw the BE, but here I am trying to add the if activity so the required/filtered data only will get uploaded.

can you help me with this scenario?

@Anirudh_Tugawe

Input= "7276176684shaenjk"
Output= System.Text.RegularExpressions.Regex.Match(Input,"\d{10}").Value

If
  Output.Length.Equals(10)
Then
    \\ Do required process
Else
   Throw New BusinessRuleException("exceptionMessage")
End If

Regards

thanks for the quick response, I i am using REF and getting the value from the queue.
in_transactionitem.specific.content(“IDno”).tostring

so i have to add the REGEx in the if condition? or as a varible?

Hi @Anirudh_Tugawe

Assign the in_transactionitem.specific.content(“IDno”).tostring to a variable and pass that variable in the output syntax.

Check below:

Input= in_transactionitem.specific.content("IDno").tostring

Output= System.Text.RegularExpressions.Regex.Match(Input,"\d{10}").Value

If
  Output.Length.Equals(10)
Then
    \\ Do required process
Else
   Throw New BusinessRuleException("exceptionMessage")
End If


Regards

okay okay I am just doing it immedietly, thanks in advance

1 Like

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