Variable changes after it is passed as an 'in argument' to another workflow

I have a Workflow called ‘Test_Iterator’ which contains a variable called ‘problem’. It passes ‘problem’ as an input argument (i.e. called ‘in_DataTable’) to another workflow called ‘Iterator’. But when the ‘Iterator’ workflow executes, for some reason the original ‘problem’ variable is being changed and I cannot figure out why. (i.e. I do not see any assignment statements that would cause this variable to change, either in ‘Test_Iterator’ or in ‘Iterator’).
Itorator.xaml (30.2 KB) Test_Iterator.xaml (31.7 KB)

The workflows are missing references when I tried to open, anyway, I don’t find the argument as Problem in the workflow iterator. Not sure if you have created it .

Can you recheck if you are initializing the values after passing it to the workflow or if you are assigning some other value after assigning the variable to the argument?

2 Likes

Hello,

Sorry, to execute the program you will also need the following 2 files (attached):

\Input\problem.xlsx
\Output\solution.xlsx

When you execute Test_Iterator.xaml, the first thing it will do is open problem.xlsx (under a subdirectory called Input) and assign it to the variable ‘problem’.

Then, Test_Iterator.xaml will invoke Iterator, passing the problem variable as an input argument (which is referenced as in_DataTable in Iterator).

Problem.xlsx (9.8 KB) Solution.xlsx (9.9 KB)

Hello again,

To make this easier to troubleshoot, I have stripped down the code to its bare essence. Attached are the 3 files required (note they can all just be in the same directory now). Here is what happens:
(1) I execute Test_Iterator.xaml. It reads problem.xlsx and assigns it to a DataTable variable called ‘problem’. It also displays ‘problem’ to the console.
(2) It then invokes the file Iterator.xaml, passing ‘problem’ to the input parameter in_Position.
(3) Iterator.xaml sets out_Position equal to in_Position, and then modifies out_Position by updating one of its cells to be “X”.
(4) Test_Iterator.xaml receives out_Position from Iterator.xaml, assigning it to a different variable (called the variable this_position).
(5) Finally, Test_Iterator.xaml redisplays ‘problem’ to the console, but this time it has changed. Instead of being its original value, it now takes on the value of out_Position.

Summing up, I’m trying to prevent the value of ‘problem’ from changing after it has been passed as an input parameter to Iterator.xaml. I don’t understand why it is changing, since I do not have any assign statements which act upon ‘problem’.

Itorator.xaml (6.2 KB) Test_Iterator.xaml (20.0 KB) Problem.xlsx (9.8 KB)

Hello again,

Please disregard, I was able to work around the issue. Apparently when I assign out_Position = in_Position, it assigns by reference rather than by value (i.e. hence any subsequent assignments to out_Position also impact in_Position). I worked around it by creating a separate Clone.xaml to copy the contents in_Position into a fresh DataTable called out_Position.

I’m a newbie at UIPath and didn’t realize that assignments worked this way.

Sincerely,
Ashley

2 Likes

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