Hi, I get the below error when I am trying to read excel files one by one using for each loop and write to queue using reframework. I am invoking WriteDataToQueue.xaml from GetTransactionData.xaml.
For Each: Object reference not set to an instance of an object.
what is all included in your âinâ portion of the for each loop? It is cut off in your screenshot
Object reference not set to an instance of an object generally means you are trying to reference a null value or an object that is null. Verify your string key is correct (i believe it is case sensitive) and verify that the value in excel is exactly what you expect. Iâm guessing it has to do with the object you are looping over that is being cut-off in the screenshot though
It is failing before it does any looping. The circled part is cut off. Can you show the full text from this circled part?
EDIT: Also, re-reading your comment, the InputDataPath in your config is just a single string. What exactly are you expecting to loop over in your for each loop?
I am trying to loop data from excel sheets â Read a fileâs contents, write to queue, process some steps & move to the next file. In short, this is what I am trying to achieve.
InputDataPath â I have defined the path from which excel files should be picked. I am trying to loop excels from this path
Ok, to do that you need to tell uipath that you want to pick up all excel files from that path. Right now it is just saying for each object in string (which doesnât make any sense).
Change the TypeArgument in the for each property to be String if it isnât already. Then change the for each loop so it is iterating over Directory.GetFiles(in_config("InputDataPath").ToString,"*.xlsx")
The Directory.GetFiles method returns an array of string, where each string in the array contains the full file path for each file in that directory. I am filtering it so it only picks up files ending in .xlsx, but you can remove that filter entirely or change the extension (e.g. change to .xls to include .xlsm, .xls, .xlsb, etc files in your array). Then your for each loop will take one string at a time to process
EDIT: You can also change the SearchOption in your Directory.GetFiles method, which would allow you to search all subdirectories. If you want to do that, just alter it so it includes⌠"*.xlsx",SearchOption.AllDirectories) at the end
EDIT #2: Youâll also need to change your excel scope so it just says item instead of "Data\Input\CustomerStockDetails\" + item. And since you changed the TypeArgument of the for each loop earlier, you can just have it be item instead of item.ToString since item is already a string
@AkshaySandhu
That did not help either. Attaching my workflow, if you can have a look.
I am calling Dispatcher_for_Queue.xaml from InitAllSettings.xaml.
Assign your dictionary out_Config argument when you invoke the Dispatcher workflow as this was blank and wasnât feeding in your in_config key:value pairs :
I had tried with typeargument as both string and object but neither worked. I have updated the argument assignment while invoking the file as well.
But the issue is not resolved. StockData_Project_1.zip (1.1 MB)
Are you getting the exact same error in the same place? I have just tried your workflow and it worked without any issues. Not sure if restarting the robot service/machine would help here.
Could you please validate that you donât have âin_configâ listed as a variable? If you have both an argument and a variable with the same name, it will always take the value of the variable, since it goes with the most local scope possible