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 II
Resolver II

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 II
Resolver II

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 Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (4,060)