In Switch activity, how to match the file name read in a folder with the queue item?

I am on a workflow, where I am already able to add the list of files in a folder to a orchestrator queue and perform few actions. Now, I have to proceed with the next set of action using switch activity:

For example, suppose there two items (ABC.xlsx and DEF.xlsx) in a folder and these are added to the orchestrator queue. Now, I am reading the file name in the folder and then based on the file name, I have to perform certain action. Example, for the file name with ABC, I have to open ESPN browser and for the file name with DEF, I have to open Netflix browser.

The challenge is to read the file name (ABC) in the folder and then compare it against the queue item (Transaction item 1). If both are same (ABC), then it should proceed with the next set of action - open browser ESPN and perform next set of action.

Can anyone help, please?

Attaching the screenshot for reference.

.

@Karunamurthy

Ideally you need to go with if condition Name.Equals(in_Transactionitem.SpecificContent("Name").ToString)

If you want to use switch only then use If(Name.Equals(in_Transactionitem.SpecificContent("Name").ToString),"Case1","Case2")

And also instead of getfilename you can use getfilenamewithoutextension

Cheers

Hi @Karunamurthy - Trying to understand, whatever the files that folder has, those will be loading to the Orchestrator queue. Then, why again comparing the file name from the Orchestrator queue with the one in the folder.

I guess your process of steps should be like

  • Get the file name from the Orchestrator queue
  • Based on the file name perform the actions

If this is you are expecting, you can use switch case in your code the condition should be

If(Transaction.SpecificContent("FileName").ToString.Equals("ABC.xlsx"),"ABC", If(Transaction.SpecificContent("FileName").ToString.Equals("DEF.xlsx"),"DEF", "Default"))
  • Transaction is the output variable of Get Transaction Item

Hi,

I think It may be better to check if there is file which matches with queueitem first, then use Switch, as the following.

filenames = System.IO.Directory.GetFiles("folder").Select(Function(f) System.IO.Path.GetFileName(f).ToLower()).ToArray()

Regards,

1 Like

Hi Yoichi,

Thank you for the suggestion!

I tried as per your suggestion but getting the error “If: Object reference not set to an instance of an object.”. Sharing the screenshot below for your reference. Can you help?

Regards,
Karuna

Hi @ushu,

Thank you for the suggestion!!!

Your understanding is correct.

If the file name from the orchestrator queue varies every time, what would be the code. ABC and DEF file name was just an example to explain the requirement. Can you also show the variables to add?

Regards,
Karuna

Hi @Anil_G,

Thank you for the suggestion!

What does “Case1”, “Case2”?

If the file name in the orchestrator queue varies every time, what would be the code to use in switch activity?

Regards,
Karuna

@Karunamurthy

  1. Case 1 and case2 are the case names that you give for requried cases…in your case it might be the filenames
  2. I am trying to match the filename in queue with the name in the name variable…if matched then go to case 1 else go to case2

cheers

its working once check your strFromQueue.tolower value
or you can use this in if condition Name.Any(function(r) r.Contains(“place here your queue item value”))

Seems pointless to add the queue item, then get it back out and compare it to the file. Why not just read the files, loop through that array, and do what you need to do for each file?

If you have some other reason to create them as queue items and process them later, then just store more than the filename in the queue item. Store the path and whatever other values you need, and process right from the queue item rather than re-reading the files in the folder.

Also, you’re wasting effort creating these variables to assign the values to. Get rid of the Files and Name variables. Just use the System.IO and Path.GetFileName expressions directly in your For Each and Switch.

It might help if you gave us a description of your overall process because it sounds like you’re going through it in a convoluted way.

Hi,

Can you check content of strFromQueue? Did you set it from your queue?

Regards,

@Karunamurthy - In the above scenario, do you want to compare the Transaction Item name with the file name in the folder ?

Can you explain in detail, adding variables mean

Hi @ushu,

Correct, I want to compare the transaction item name with the file name in the folder and then need to process file in the folder using switch activity. My actual requirement is to process the files in queue in switch activity.

If there are 2 excel files (ABC and DEF) in the folder, I have moved them to Orchestrator queue and perform certain clean up before the switch activity.

When it comes to switch activity, for each file in the folder, I have different set of action. I want to perform the required action in switch activity in queue. First ABC file should be processed in switch activity and then get the DEF file from the folder and process it. But now both ABC and DEF is getting processed without processing the action in queue.

Regarding variables, you can ignore them now.

Sorry, if I am confusing you.

Regards,
Karuna

@Karunamurthy -

1)If you see in the above switch activity screenshot, TransactionItem.SpecificContent(“FileName”).ToString this exp represents getting the file name from the queue and then .Equals("ABC.xlsx") exp represents comparing the queue output which is a file name with ABC.xlsx

No, as I mentioned above TransactionItem.SpecificContent("FileName").ToString represents the queue output. Before switch use Get Transaction Item activity and assign the output variable as TransactionItem

That is how, the queue process it, when you are trying to load the files from the folder to queue, it loads the same order as in the folder.

Ex: First ABC file, next DEF file to the queue

So, while retrieving from the queue, it follows the same order. It gets ABC file then DEF file etc. So, I guess again you need not to compare again the queue file name with the file in the folder as the queue gets the filenames in the same order as it is in the folder

Also, can you confirm the file names in the folder will always be same or varies

Hi @ushu,

The file names in the folder varies every time when we run the automation daily. In this case, what would be code?

Thank you so much for your help.

Regards,
Karuna

Hi @Anil_G,

Thank you for the suggestion.

In my case, ABC and DEF are just an example. If the file name in the folder varies each time when running the automation, what would be Case 1 and Case 2?

Regards,
Karuna

@Karunamurthy

Can you please explain your requirement…

Because switch case can be used when you have cases like a,b,c etc …when its changing we only compare…and either put it into case A or B or C or etc

Cheers

@Anil_G,

I understand. I my case, there are 70 types of files with different names so I need to add 70 cases. Correct?

Regards,
Karuna

@Karunamurthy

What is the requirement?

For every file there is a different task?

Cheers

@Anil_G

Yes, each file has different task which I will be adding in the switch activity.

The requirement is that suppose there are 10 files in the folder like ABC.xlsx, DEF.xlsx, GHI.xlsx, etc.,. I have added them to queue item, therefore, ABC will be 1st queue item and in the switch activity even though there are 10 different task are configured each file, it should only perform ABC file in the folder as per the queue. Now, 2nd transaction item DEF should be follow the same process. Like wise for other remaining files in the folder as per queue.

Hope I am clear with my requirement.

Regards,
Karuna