cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Nithin_Vanam
Helper II
Helper II

How to dynamically construct a variable name in the Variable function

Hello,

 

I have a list of variables (webbrochure1 to webbrochure10) that can potentially store a value. I was trying to run a Do Untill loop based on an index and dynamically read the content of the variables. something like : variables(concat('webbrochure',variables('Brochure Index')))

 

I guess maybe i could use Arrays to store the same data to loop through the index but not able to think through it.

 

The issue is for some reason the variables function does not seem to accept anything but the name and i get the following error when i try to output this in a compose action:

 

Request to XRM API failed with error: 'Message: Flow client error returned with status code "BadRequest" and details "{"error":{"code":"InvalidOpenApiFlow","message":"Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The template action 'Compose_2' at line '1' and column '10435' is not valid: \"The template function 'variables' is not expected at this location.\".'.'."}}". Code: 0x80060467 InnerError: '.

When a row is added, modified or deleted
contains(...)​
bool(...)​

 

 

Below is the flow:

 

Flow - Variables - Error 1.png

 

Any suggestions on how i could change the variable name inside the variable function ? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
muralidharan
Resolver III
Resolver III

Hi @Nithin_Vanam ,

I don't think, you can pass or construct the variable name dynamically. During each save, Power Automate validates whether the given variable name is initialized before its usage or not. If you construct the variable name dynamically it can't validate it and it is throwing template validation error.

 

This will work, 

@{concat('temp_',variables('index'))}

But the below one will fail.

variables(concat('temp_', variables('index')) )

 

Hope this is clear.

 

Thanks,

Murali

 

Please Like and Mark this as Answer if it resolves your Issue.

View solution in original post

1 REPLY 1
muralidharan
Resolver III
Resolver III

Hi @Nithin_Vanam ,

I don't think, you can pass or construct the variable name dynamically. During each save, Power Automate validates whether the given variable name is initialized before its usage or not. If you construct the variable name dynamically it can't validate it and it is throwing template validation error.

 

This will work, 

@{concat('temp_',variables('index'))}

But the below one will fail.

variables(concat('temp_', variables('index')) )

 

Hope this is clear.

 

Thanks,

Murali

 

Please Like and Mark this as Answer if it resolves your Issue.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (4,206)