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

How do I use JSON function with a repeating section gallery?

Hi

I'm using a gallery and a button to create a repeating section with a couple of dropdowns.

Until now and following a tutorial, I used the following code to concatenate the selected values in it and save it in a SP List column:

This was in the Plus button (OnSelect) to add a row:

Collect(  
NewCollection,  
   {  
      CItemSerialNumber: Text(Last(NewCollection).CItemSerialNumber + 1),  
      Clevel: "",  
      Ctc: "",  
     Cdescription: ""  
  }  
)

 

This was in the Save button (OnSelect):

UpdateContext(  
    {  
        NewItemsString: Concat(  
            Gallery2.AllItems,  
            Concatenate(
                "LUN:",TextInput2.Text,";"
                ,"Size:",Text(Dropdown8.Selected.Size),";",
                "SKU",Dropdown9.Selected.Value,";",
                "|"
            )  
        )  
    }  
)

 

And this was on the Default property of the Data Card holding the Gallery:

NewItemsString

 

 

However, in Flow, processing that single string composed of concatenated things in it has become troublesome, so I started looking for an alternative and I found the JSON function which saves the string in JSON format, which would be a lot easier to handle in Flow.
But I can't seem to understand how to translate the previously posted logic to JSON...
Can you help me?
Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

From your code, it seems that you are submitting the entire data from your NewCollection data source to Power Automate when you click on the Save Button. I will start from this assumption.

 

Gallery2.AllItems is just pointing to NewCollection, but with a layer of indirection. As you are Collect()ing to the data source, you can reference it directly to serialize to JSON.

 

On your Save Button, you can just: 

 

Set(NewCollectionJson, JSON(NewCollection, JSONFormat.IgnoreUnsupportedTypes));

 

Read the reference, for the JSON function. you can also use JSONFormat.IndentFour to display json for human eyes.

 

Check the generated JSON on a Label. If it is looking right, also add your submit function to the save button: 

 

MyPowerAutomateSaveFunction.Run(NewCollectionJSON);

 

Note that you are sending a single parameter of type string

From that point on, is just going to Power Automate and add Parse JSON there to interpret the json string back into an object. 

 

 

 

 

 

 

View solution in original post

9 REPLIES 9
v-siky-msft
Community Support
Community Support

Hi @Morke ,

 

Could you please share more details about what do you want to implement in flow?

I can understand what do you want to achieve in PowerApps since I found the tutorial, but what do you want to do in flow? Do you just want to pass the concatenated string to the flow? I think you can directly pass the concatenated string to flow.

If you want to know how to compose the concatenated string from the Array in flow, please try this:

First to use 'Append to array variable' action to create an array that concatenates each field and value, Then use Join data operator action to return a string from an Array separated by a ”|“.

Snipaste_2020-05-07_09-28-42.png

Result:

Snipaste_2020-05-07_09-35-19.png

Hope this helps,

Sik

 

 

 

 

 

Thank you for your reply. I'll try your solution and let you know if it works for me.

As for what I want to do in Flow, I need to supply an array of arrays variable to an ARM Template (which is just a glorificated JSON Azure uses)
Since I was having trouble understanding how to create an array of arrays from a single concatenated string that doesn't have any formatting besides the separators ( ";" between each component of an item and "|" between each item), I started to research on how would the best approach be, and maybe sending a JSOn formated string to Flow instead of a simple string would make things easier when using it.
But i'm not sure and that's the reason of this post.

The reason I need an array of arrays is that the ARM Template has a Copy function that lets you loop through an array of arrays (received as a parameter variable).

Is there a specific reason for not using PowerApps JSON() function? 

You can serialize your collection directly to JSON on PowerApps, and submit the JSON string to power Automate. 

The you can just Parse JSON() on Power Automate to work with the data as an object and make any manipulation you need to make the ARM Template. 

Yes, there's a specific reason:
My lack of knowledge, hahahaha.
No, seriously. That string is created by a concatenate of a Repeating Gallery. I followed a tutorial to do it but I'm struggling on how to transform the current way of doing it to use JSON instead.

JSON() can serialize any collection or Record. 

I usually use it in conjunction with Set(), so I can debug the JSON string on PowerApps end before I submit. 


simple case: 

Set( json_var, JSON(MyCollection, JsonFormat.IgnoreUnsupportedTypes));

Then I submit it to Power Automate:

PowerAutomateFunction.Run(json_var);


On Power Automate: 

A single params parameter receives the JSON string.

the Parse JSON action interprets the JSON string according to a JSON schema and makes it available to the Flow as actionable objects. It also has a convenient schema generator, all you have to do is supply the schema generator with a data sample, and it generates the schema for you. 

 

Advanced use: 

 

Instead of submitting multiple parameters in PowerApps side when you PowerAutomateFunction.Run(), you can pack everything in a single JSON parameter instead. 

Set(json_var,
    JSON(  //you can write a literal object here and pack several variables or collections on a single string
        {

            savelocation: "/locationdata/",

            data: mydatacollection

        },
        JsonFormat.IgnoreUnsupportedTypes

    )
)

 

One must remember to update the schema on Parse JSON once the submitted data changes, to access the data on that side. 

 

Using this technique of packing everything in a single JSON string, it becomes unnecessary to remove and re-add the Flow on PowerApps if you change the parameters later on. 

@TiagoFreire Thank you, that's very helpful. I appreciate it.
I don't want to ask for a step by step guide or to hand me over the solution, but I might need a bit more of guidance to accomplish what I intend to.
Ok so you are creating a JSON object and saving that into a variable. No problem there.
However, where do I use the JSON function in my solution to do that, considering I'm using a repeating gallery?

In here, with this Plus button in this Data card and with this code in the OnSelect Property, I understand that I'm creating a collection every time someone presses it:

Collect(  
NewCollection,  
   {  
      CItemSerialNumber: Text(Last(NewCollection).CItemSerialNumber + 1),  
      Clevel: "",  
      Ctc: "",  
     Cdescription: ""  
  }  

  This gallery has "NewCollection" collection as a DataSource so every time someone presses the button an creates a new NewCollection, a new "row" replicates itself:
DatacardGallery.png

 

if you want to save what you created, you press the Save button on the DataCard which has this OnSelect Code. This creates or (updates if it already exists) NewItemsString variable, which is a concatenation of all gallery items, which are, in turn, being concatenated as well:

UpdateContext(  
    {  
        NewItemsString: Concat(  
            Gallery2.AllItems,  
            Concatenate(
                TextInput2.Text,
                ";",Text(Dropdown8.Selected.Size),
                ";",
		Dropdown9.Selected.Value,
                ";",
                "|"
            )  
        )  
    }  
);


Lastly, the DataCard "Default" is set to NewItemsString variable, which gets updated everytime you press the Save button.


I suspect I need to modify the Save button which is the one creating a concatenated string. Instead, I need to use the JSON function to create the function object with the current gallery items
However, I'm not sure in which way I need to modify it.
Can you point me in the right direction?

 

From your code, it seems that you are submitting the entire data from your NewCollection data source to Power Automate when you click on the Save Button. I will start from this assumption.

 

Gallery2.AllItems is just pointing to NewCollection, but with a layer of indirection. As you are Collect()ing to the data source, you can reference it directly to serialize to JSON.

 

On your Save Button, you can just: 

 

Set(NewCollectionJson, JSON(NewCollection, JSONFormat.IgnoreUnsupportedTypes));

 

Read the reference, for the JSON function. you can also use JSONFormat.IndentFour to display json for human eyes.

 

Check the generated JSON on a Label. If it is looking right, also add your submit function to the save button: 

 

MyPowerAutomateSaveFunction.Run(NewCollectionJSON);

 

Note that you are sending a single parameter of type string

From that point on, is just going to Power Automate and add Parse JSON there to interpret the json string back into an object. 

 

 

 

 

 

 

Hi @Morke ,

 

My above flow is to concatenate the Array to be a string by separators(; and |) as what you do in PowerApps.

However, I just found you just want to create an array from that concatenated string, right?

If so, I think you just pass the NewCollection to Flow by JSON function, and @TiagoFreire has provide such workaround, I think it should make sense for your case.

Please feel free to post back if you still need assistance.

Sik

 

I am new to this and am in the same boat. The only difference is I am trying to submit the data from the gallery to my SharePoint single line text. I am not sure how to implement JSON to send the data as a string to SharePoint list.

Do I add the code for JSON to the code or to the item property of the gallery

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (752)