web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : rGOSo0LBouQLTthYEE1bWX
Power Automate - General Discussion
Answered

Dynamic variable names and objects

Like (0) ShareShare
ReportReport
Posted on 31 Aug 2023 11:05:34 by 256

Hello,

 

I need your help in finding the best solution for this situation:

I have and object with some attributes that could contain one ore more values. These attribute names differ with only one letter (in fact is a number) for example: A1, A2, A3.

Let's assume the object will look like this:

 

{
"ObjectTitle":"Some Title",
"A1":[
	{
	"Item":"A1I1",
	"Value":"A1V1"
	},
	{
	"Item":"A1I2",
	"Value":"A1V2"
	}
],
"A2":[
	{
	"Item":"A2I1",
	"Value":"A2V1"
	}
],
"A3":[
	{
	"Item":"A3I1",
	"Value":"A3V1"
	},
	{
	"Item":"A3I2",
	"Value":"A3V2"
	}
]
}

 

Now I need to collect the values of these attributes in their respective array variables arrA1, arrA2, arrA3.

I have managed to to this for one of the arrays:

 

Flow.jpg

Where "Apply to each" condition is: variables('objContract')?['A1']

and "Append to array variable" value is: item()?['Value']

 

Now, my problem is that I have to do this for about 10 attributes.

So the question is: there is a way not to repeat the "Apply to each" for every array variable but to create a bigger "Apply to each" (for an numeric array [1,2,3]) and use some dynamic variable names to populate content for all arrays? (because all depends on a single letter)

 

Kind Regards,

Lucian

  • Lucian Profile Picture
    256 on 04 Sep 2023 at 18:24:42
    Re: Dynamic variable names and objects

    Hi @Chriddle ,

     

    Thank you for your response. I did not have the chance to test in into "production" but from the test following your instruction it seems that it would be exactly what I need.

     

    So thank you very much for your time.🙏

     

    Kind Regards,

    Lucian

  • Verified answer
    Chriddle Profile Picture
    7,934 Super User 2025 Season 2 on 01 Sep 2023 at 12:08:19
    Re: Dynamic variable names and objects

    Not sure if I've gotten that 😉

    The result should be something like this?

    [
     {
     "Name": "A1",
     "Values": [
     "A1V1",
     "A1V2"
     ]
     },
     {
     "Name": "A2",
     "Values": [
     "A2V1"
     ]
     },
     {
     "Name": "A3",
     "Values": [
     "A3V1",
     "A3V2"
     ]
     }
    ]

     

    Then you first need a Select to get the property names and a second Select to get the values for each of these names:

    Chriddle_1-1693569800087.png

     

    Select

    From:

    skip(
    	xpath(
    		xml(
    			json(
    				concat(
    					'{"root":',
    					outputs('Data'),
    					'}'
    				)
    			)
    		),
    		'/root/*'
    	),
    	1
    )

    Map:

    xpath(xml(item()),'name(/*)')

     

    Select 2

    From:

    union(body('Select'), json('[]'))

    Map Name:

    item()

    Map Values:

    xpath(
    	xml(
    		json(
    			concat(
    				'{"root":',
    				outputs('Data'),
    				'}'
    			)
    		)
    	),
    	concat('/root/',item(),'/Value/text()')
    )

     

  • Lucian Profile Picture
    256 on 01 Sep 2023 at 11:11:55
    Re: Dynamic variable names and objects

    Hi @Chriddle ,

     

    Thank you for your response that is very usefull for another project where I need to collect all of the attribute values into a single array.

     

    But this time what I would like to achieve without repeating steps (if possile) to create three arrays with the "corresponding" values.

     

    For example, the expeced result would be:

    A1Array shoud contain the values for A1 property:

    A1V1

    A1V2

     

    A2Array shoud contain the values for A2 property:

    A2V1

     

    A3Array shoud contain the values for A3 property:

    A3V1

    A3V2

     

    Kind of create "n" tables/arrays (in the example above 3) with their corresponding values.

     

    Or, completing your idea - like distributing the AnVx values to the corresponding AnArray variable without creating n "Apply to each" loops.

     

    Kind Regards,

    Lucian

  • Chriddle Profile Picture
    7,934 Super User 2025 Season 2 on 31 Aug 2023 at 13:57:15
    Re: Dynamic variable names and objects

    Try xPath:

    Chriddle_0-1693490054972.png

    Select:

    From:

     

    skip(
    	xpath(
    		xml(
    			json(
    				concat(
    					'{"root":',
    					outputs('Data'),
    					'}'
    				)
    			)
    		),
    		'/root/*'
    	),
    	1
    )

     

    Map Item:

     

    first(xpath(item(), '//Item/text()'))

     

    Map Value:

     

    first(xpath(item(), '//Value/text()'))

     

     

    returns

    Chriddle_1-1693490188051.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2

Loading complete