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

Validation on submit button (ForAll/IF)

Morning,

 

I am trying to add an IF statment for validaton on the below ForAll Statement.  


This is for a popup that have 4 icons and they have to be selected to set of the rest of the statement.  I am unsure on where to have the IF statement.  I am pretty certain it needs a isBlank function in there too.

 

Any help would be great.  Thanks! 

ForAll(
    Filter(
        collectSelectedOptions,
        Selected
    ),
    Switch(
        IconName,
        "Display",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Monitor",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Base Station",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Base Station",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Keyboard",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Keyboard",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Mouse",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Mouse",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        )
    )
);
UpdateContext({ShowSuccessPopup: true})
8 REPLIES 8
Super User III
Super User III

@Joko 

Have you looked at the Errors function?  You can use that to determine if there were any errors during your patching.

Also, maybe shorten your formula a little?

 

ForAll(
    Filter(
        collectSelectedOptions,
        Selected
    ),
    Patch(
    	'RoomDamageApp - Room Damage',
    	Defaults('RoomDamageApp - Room Damage'),
    	{
    	ItemDamaged: Switch(IconName,
    		"Display", "Monitor",
    		"Keyboard", "Keyboard",
    		"Mouse", "Mouse"),
    	PC: Label_Computer_Result.Text,
    	Room: label_roomnumber.Text,
    	Comments: CommentBox.Text,
    	Staff: Label_StaffMember_Result.Text,
    	Period: {
    		Id: Dropdown_Period.Selected.Id,
    		Value: Dropdown_Period.Selected.Value
                }
        }
        )    
);
//Here check for errors
If(!IsBlank(Errors('RoomDamageApp - Room Damage')), //whatever you want to do here...
UpdateContext({ShowSuccessPopup: true})

 

I hope that helps some for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hi there thanks for your reply.

 

the If Statement is after the main code section.  I think this is still running the code but not excecuting when i press the submit button.

 

I have edited to this for now.

ForAll(
    Filter(
        collectSelectedOptions,
        Selected
    ),
    Switch(
        IconName,
        "Display",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Monitor",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Base Station",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Base Station",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Keyboard",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Keyboard",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Mouse",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Mouse",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        )
    )
);
If(!IsBlank(ItemDamaged), UpdateContext({pleasePickItem: true}),UpdateContext({ShowSuccessPopup: true}))

So the pleasepickitem is a label that shows up when nothing is selected.  Which is fine but the 2nd popup doesnt fire when the rule is set to false.


Thanks! 

@Joko 

Your Errors function should specify the name of your datasource (in this case the 'RoomDamageApp - Room Damage') Not the column name you have in your formula.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Wouldn't that just work if the sharepoint list is blank ? Or am i confused?


Thanks


@Joko 

No, the Errors function specifically needs to look at the DataSource and optionally a record to determine if there are errors.

   Errors(dataSource) will return a colleciton of any errors for the datasource.

   Errors(dataSource, aRecord) will return an error record for any error in the datasource for a specific record.

 

Take a look at the Errors function for some more examples.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Thanks for your reply, although i can't seem to get this to work. 

 

123123123.PNG

 

Just for context this is the popup i have, the 4 icons i would like to have the validation on.  I can get it to show a popup telling people to select an icon, however if i do select an icon, the button doesn't work.  Very confused.  

 

Thanks.

 

Edit: This is the validation i am using now: 

);If(!IsBlank(Errors('RoomDamageApp - Room Damage')),UpdateContext({pleasePickItem:true}),UpdateContext({ShowSuccessPopup:true}))

 

So when i don't select one, i get the popup and sharepoint doesn't update - which is great.  But when i do select one, i still get the same pleasepickitem popup but sharepoint DOES update.  Its like it's not looking at the false reading.

@Joko 

Can you let me know your formula you have for selecting the icons?  That would be helpful.

Also, your full formula on the submit button.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Sure,

 

Code for selecting the Display / Base / Keyboard / Mouse

Patch(
    collectSelectedOptions,
    LookUp(
        collectSelectedOptions,
        IconName = "Display"
    ),
    {
        Selected: !LookUp(
            collectSelectedOptions,
            IconName = "Display",
            Selected
        )
    }
)

Code for Submit button:

 

ForAll(
    Filter(
        collectSelectedOptions,
        Selected
    ),
    Switch(
        IconName,
        "Display",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Monitor",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Base Station",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Base Station",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Keyboard",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Keyboard",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        ),
        "Mouse",
        Patch(
            'RoomDamageApp - Room Damage',
            Defaults('RoomDamageApp - Room Damage'),
            {
                ItemDamaged: "Mouse",
                PC: Label_Computer_Result.Text,
                Room: label_roomnumber.Text,
                Comments: CommentBox.Text,
                Staff: Label_StaffMember_Result.Text,
                Period: {
                    Id: Dropdown_Period.Selected.Id,
                    Value: Dropdown_Period.Selected.Value
                }
            }
        )
    )
);If(!IsBlank(Errors('RoomDamageApp - Room Damage')),UpdateContext({pleasePickItem:true}),UpdateContext({ShowSuccessPopup:true}))

I think this is all you will need to replicate it.


Thanks 🙂 

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (27,143)