The operation 'Initialize variable' can only be used at top level | Variable cannot be initialized in Logic App scope

{tocify} $title={Table of Contents}


While working on logic app, I needed a local variable and tried to add it in Scope, however was presented with below warning

The operation 'Initialize variable' can only be used at top level.

Why it happened

Logic app by design only supports Initialization of variables on Global Level(variables are global within an instance of Logic App execution). 

However we can use the variable at any stage of your process after initialization and perform following supported actions on it .

Actions supported in variable logic app

What to do

If you need to use variable, you can  initialize it outside Scope. 

Do not get confused with Top level in error, you can initialize it before and after scope. However if you plan to use it in scope, then it should be before Scope shape.

Also note that variables also can't be initialized within conditions and loops.

Feedback to Logic App product team

Like in BizTalk, where we can initialize a variable in scope (it's life is within scope), can we have same available in Logic app too?

i.e. Provision to have local variable in Logic App Scope?

Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post