0

I wrote a PowerShell script that takes a .NET DataTable as an input parameter and inputs the the row items into SAP GUI. The script itself works just fine when executed through PowerShell, however when attempted to be invoked through UiPath Studio using the "Invoke PowerShell" activity, it throws the "Object reference not set to an instance of an object" error after processing the last row item.

It will successfully process the last row and input it into the GUI, but it then throws the error indicating that it is continuing to loop.

The main body of my logic is very simple:

 for ($i=0; $i -le ($dt_example.Rows.Count); $i++){ 
        if($i -eq $dt_example.Rows.Count){exit}
    
        #SET VALUES
        Set-Property $Val1 "text" @($dt_example.Rows[$i][0]) 
        Set-Property $Val2 "text" @($dt_example.Rows[$i][1]) 
        Set-Property $Val3 "text" @($dt_example.Rows[$i][2]) 
        Set-Property $Val4 "text" @($dt_example.Rows[$i][3]) 
        
    }

The script works fine via just PowerShell, but fails when executed through UiPath. It completes the last iteration and sets the properties, but then throws the Object error as it seems to iterate through once more.

Does anyone know of a condition or logic I can put in to prevent the null iteration from occurring? Thanks.

tmccaffrey
  • 35
  • 5

0 Answers0