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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Multiple If to generat...
Power Apps
Unanswered

Multiple If to generate JSON file

(0) ShareShare
ReportReport
Posted on by 15

I need to create a JSON file, selecting some fields/ columns that visible is true/false. How can I get it? See my code:

 

Set(
varJSONCars,
JSON(
ForAll(
ShowColumns(
GlSumario.AllItems,
"Initiation",
"Countrye"),
If(varInitiation = true,{Initiation: Initiation.Value}, If(varShowColumn = true,{Countrye: Countrye}));

),

JSONFormat.IndentFour
));
ExpSumario.Run(varJSONCars)

Categories:
I have the same question (0)
  • JorisdG Profile Picture
    on at

    The ForAll function is trying to figure out what type of record it's supposed to return which, due to the IF statements, is unclear. In such a case, it will assume the final record's "Type" is defined by the intersection of used fields in all the different If outcomes. In your case, there is no intersection so no columns are included at all.

     

    You have options though. Not sure if you intend to have the option of including both these columns (which your current logic seems to say is not possible). But in either case, you could a few other things like just removing the columns you don't want (without using ForAll):

     

    Set(tempTable, ShowColumns(GlSumario, "Initiation", "Countrye"));
    If(varInitiation = false, Set(tempTable, DropColumns(tempTable, "Initiation")));
    If(varShowColumn = false, Set(tempTable, DropColumns(tempTable, "Countrye")));
    Set(varJSONCars, JSON(tempTable, JSONFormat.IndentFour));

     

    I'm not sure you need the ShowColumns() in the beginning, that would only be needed if your GISumario has other columns you wish to discard, I guess.

     

    Hope this helps.

  • bercori Profile Picture
    15 on at

    I have a list in Sharepoint 'Create Project' where I want to select some fields to generate a CSV report. I created a gallery (GlSumari) with all the fields from the 'Create Project' list and inserted some selection boxes, where the person chooses which fields will appear in the report, clicking on these fields, to generate the report. When I click the BUTTON, it creates the JSON in a text field
    I added a text field to generate this JSON (text = varJSONCars)

    2022-06-02_22-16-27.png

     

     

     

    2022-06-02_22-26-50.png

  • Verified answer
    bercori Profile Picture
    15 on at

    Yea! It works! Thank you very much @JorisdG ! I just adjusted some things...

    1 - I added ".AllItems"

    2  - I need the "ForAll" function to show me the field correctly, otherwise it will be with codes in the excel. So I added more code, like below.

     

     

    Set(tempTable, ForAll(ShowColumns(GlSumario.AllItems,"Initiation","Countrye"),{Initiation:Initiation.Value,Countrye:Concat(Countrye, Value, ",")}));
    If(varInitiation = false, Set(tempTable, DropColumns(tempTable, "Initiation")));
    If(varShowColumn = false, Set(tempTable, DropColumns(tempTable, "Countrye")));
    Set(varJSONCars, JSON(tempTable, JSONFormat.IndentFour));ExpSumario.Run(varJSONCars)

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard