cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
robertopolo
Advocate I
Advocate I

Create array with nested Ifs

I am trying to create a function that allows me to create a JSON by pressing a button. The problem I am having is that one of the fields must be an array and it depends on what is selected, or not, in 2 ComboBox. Everything works perfectly when I create the If with 3 scenarios:

 

  1. When both ComboBox HAVE something selected.
  2. When the first ComboBox HAVE something selected and the second DOES NOT.
  3. When the first ComboBox DOES NOT HAVE anything selected and the second DOES.

 

This is the function that I have created for this case:

 

 

Set(JSONItems;JSON(ClearCollect(Items;
    ForAll(Gallery1_1.AllItems;
    {
        TAXES:
        If(
            And(!IsBlank(ComboBox4_1.Selected.id);!IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox4_1.Selected.id
                };
                {
                    id: ComboBox3_1.Selected.id
                }   
            );
            And(!IsBlank(ComboBox4_1.Selected.id);IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox4_1.Selected.id
                }
            );
            And(IsBlank(ComboBox4_1.Selected.id);!IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox3_1.Selected.id
                }
            )
        )
    }
    )
);IndentFour))

 

 

And this is the result:
Captura de pantalla 2021-09-03 100051.png

Note that in the last case it returns a null which is not valid for an array. This is the case where nothing is selected in the controls and it is not contemplated in the function.

 

The problem arises when I add a 4 scenario, when both ComboBox have nothing selected. At this point the result is that no matter what scenario is presented, the resulting array does not have any records in it.

 

This is the function that I have created for this case:

 

 

Set(JSONItems;JSON(ClearCollect(Items;
    ForAll(Gallery1_1.AllItems;
    {
        TAXES:
        If(
            And(!IsBlank(ComboBox4_1.Selected.id);!IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox4_1.Selected.id
                };
                {
                    id: ComboBox3_1.Selected.id
                }   
            );
            And(!IsBlank(ComboBox4_1.Selected.id);IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox4_1.Selected.id
                }
            );
            And(IsBlank(ComboBox4_1.Selected.id);!IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox3_1.Selected.id
                }
            );
            And(IsBlank(ComboBox4_1.Selected.id);IsBlank(ComboBox3_1.Selected.id));
            Table()
        )
    }
    )
);IndentFour))

 

 

And this is the result:

Captura de pantalla 2021-09-03 100436.png

Note that in the cases where previously there was a record, now there is nothing.

I appreciate any help you can give me, I have been fighting with this for 2 days and I am losing the battle.

1 ACCEPTED SOLUTION

Accepted Solutions

Thank you very much for your answer. The only detail with your proposal is that I cannot send any data in that array because whatever I send it will look for it in the database. Likewise, I update the post commenting that I managed to solve the problem by doing the following:

 

1.- Creating a collection with only one records and with the correct columns and data types.
2.- Use the Clear () function to delete the record and leave the collection with only the columns.
3.- In the event that both ComboBoxes do not have anything selected, do not use a blank table if not the collection.

View solution in original post

2 REPLIES 2
StalinPonnusamy
Super User
Super User

Hi @robertopolo 

 

Looks like a bug in the JSON conversion. A workaround you can try this to have value 0 (Not sure if this is acceptable)

 

Set(JSONItems;JSON(ClearCollect(Items;
    ForAll(Gallery1_1.AllItems;
    {
        TAXES:
        If(
            And(!IsBlank(ComboBox4_1.Selected.id);!IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox4_1.Selected.id
                };
                {
                    id: ComboBox3_1.Selected.id
                }   
            );
            And(!IsBlank(ComboBox4_1.Selected.id);IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox4_1.Selected.id
                }
            );
            And(IsBlank(ComboBox4_1.Selected.id);!IsBlank(ComboBox3_1.Selected.id));
            Table(
                {
                    id: ComboBox3_1.Selected.id
                }
            );
            Table({id: 0}) // Or Table({id: Text(0)})
        )
    }
    )
);IndentFour))

Note: No need to specify 4th condition

Either Table({id: 0}) // Or Table({id: Text(0)})

 

Thank you very much for your answer. The only detail with your proposal is that I cannot send any data in that array because whatever I send it will look for it in the database. Likewise, I update the post commenting that I managed to solve the problem by doing the following:

 

1.- Creating a collection with only one records and with the correct columns and data types.
2.- Use the Clear () function to delete the record and leave the collection with only the columns.
3.- In the event that both ComboBoxes do not have anything selected, do not use a blank table if not the collection.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,210)