Uipath studio on variables

Hi there,

Can i create a workflow have the same variable name in if or else. For example, i have created a logic to go either if or else. Under if sequence, i will store a variable name invoice number and else i wan to store a variable same as if sequence where the name is invoice number. Is this possible and will it cause a issue?

Hi @mark_rajkumar1

You can have the same variable name within that sequence. Just change the scope of tha particula variable and you are good to use that.


Hi @vrdabberu so in another words in if or else sequence we can assign the same variable name. Am i right?

Hi @mark_rajkumar1

Yes you are right.

In the else sequnece also you can use the same variable name.

You need to just change the scope of that variable name to outermost scope like that particular sequence.


Hi @mark_rajkumar1 ,

You can create a string variable which can hold same value in then or else sequences.

Later when the value is required in number format you can use data conversion functions in order to change the data type and use them.

If you want to use the value outside the if condition then my suggestion would be the above method.



If the purpose of the variable is same in both case, just use single variable with scope above the if else.

If purpose of the variable is different for if and else part, better to declare variable with different name to avoid confusion.

Ashok :slight_smile:



string invoiceNumber;

if (condition)
    invoiceNumber = "12345"; // Variable 'invoiceNumber' in 'if' block
    invoiceNumber = "67890"; // Variable 'invoiceNumber' in 'else' block

Console.WriteLine(invoiceNumber); // Outputs the value of 'invoiceNumber' based on the condition

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