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})
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.
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!
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.
Wouldn't that just work if the sharepoint list is blank ? Or am i confused?
Thanks
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.
Thanks for your reply, although i can't seem to get this to work.
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.
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.
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 🙂
User | Count |
---|---|
183 | |
123 | |
88 | |
45 | |
42 |
User | Count |
---|---|
250 | |
159 | |
127 | |
78 | |
73 |