Reset to Default Value in a For Each

Dear Community,

recently I’m facing an unusual error: After each loop in a For Each my variable is set back to its default value although a new value was assigned to it. I would expect the variable to keep the newly assigned value and not go back to default. Am I right?
Unfortunately I’m new to the Community Forum and cannot attach the Workflow File. Following you can see a screenshot with the complete workflow, the variabes and the output.

Thanks in advance!

Hi
Welcome to uipath community
hmm… yah it should give us the updated value even in second iteration of for each row loop
but this looks strange
fine lets do one thing use a assign activity before to the FOR EACH ROW loop and make the variable definition like
test = "New Value 123"
and remove the default value in the variable panel and try once pls
make sure that the variable is set with global scope in the variable panel under scope column (like whole sequence)

Cheers @Fassih

2 Likes

@Fassih
This is a scope issue, as Palaniyappan mentions above. Since the variable has the scope of “Assign vairable to Test” sequence it is created when the sequence starts and deleted when the sequence ends. So your value is being created with the default value, set to the new value, and then deleted for each iteration of the loop. Change the scope to a larger scope and the variable will persist with the values it is given (IMO global scope is overkill, I would only use as large a scope as is needed).

2 Likes

Thank you @DanielMitchell, that solved the problem! I wasn’t thinking that the scope of the variable would reset its value. Good to know for the future!

Also thanks to you @Palaniyappan!

Best regards
Fassih

2 Likes

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