cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MikeAnderson
Level: Powered On

Checking for empty field values in records in gallery

I have a Gallery that displays 1 or more records based on user selection.  The record(s) contain multiple fields, of which I need to verify that 2 fields (Asset ID, VIN) in all records displayed in the gallery contain values when the user presses a save button.  I have the following code in place and it works, but I'm curious if there is a more efficent way to do this, as it feels a bit clunky to me (creating a collection to hold the rowcounts of blank records).

 

Here is the screen:

2019-09-19 10_06_41-Equipment Requester Admin - Saved (Unpublished) - PowerApps.png

 

Here is the code:

Clear(ValidateCollection);

//Create a new collection to check if all required fields are populated
ForAll(
    EquipmentGallery_DetailsScreen.AllItems,
    If(
        IsBlank(AssetIDTextInput_DetailsScreen.Text) || IsBlank(VINTextboxInput_DetailsScreen.Text),
        Collect(
            ValidateCollection,
            {RequestID: RequestIDDataLabel_DetailsScreen.Text}
        )
    )
);
//If we have rows, then we have blank required field entries
If(
    CountRows(EquipmentGallery_DetailsScreen.AllItems) <> 0,
    "Save code goes here", 
UpdateContext({conValidationErr: true, conValidationMessage: "!"}) )


I use the context variable to drive user feedback for the required fields.  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Checking for empty field values in records in gallery

Hey @MikeAnderson, here's the way I would go at it. In the EquipmentGallery_DetailsScreen gallery I would hide (Visible property = false) a text label with the following:

 

IsBlank(AssetIDTextInput_DetailsScreen.Text) || IsBlank(VINTextboxInput_DetailsScreen.Text)

which will produce a boolean (true/false) value for each row of the gallery (true if one or more of those text inputs are blank, false otherwise). Next, I would count how many of those text labels are true like so:

CountIf(EquipmentGallery_DetailsScreen.AllItems.lblBlankItems, lblBlankItems.Text = "true")

 where lblBlankItems is the name of the aforementioned text label. Note that the "true" is a text value and in double-quotes as we are checking the label's text, not for a true/false value in the typical sense. If this count is equal to zero, all of those fields have an entry. If not, one or more is missing an entry.

 

If you did something like :

If(
    CountIf(EquipmentGallery_DetailsScreen.AllItems.lblBlankItems, lblBlankItems.Text = "true") = 0,
    "Save code goes here", 
    UpdateContext({conValidationErr: true, conValidationMessage: "!"})
)

I think you could cut out the entire collection business altogether.

 

Let me know if that works for you or not; I'd be happy to follow up if needed!

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Checking for empty field values in records in gallery

Hey @MikeAnderson, here's the way I would go at it. In the EquipmentGallery_DetailsScreen gallery I would hide (Visible property = false) a text label with the following:

 

IsBlank(AssetIDTextInput_DetailsScreen.Text) || IsBlank(VINTextboxInput_DetailsScreen.Text)

which will produce a boolean (true/false) value for each row of the gallery (true if one or more of those text inputs are blank, false otherwise). Next, I would count how many of those text labels are true like so:

CountIf(EquipmentGallery_DetailsScreen.AllItems.lblBlankItems, lblBlankItems.Text = "true")

 where lblBlankItems is the name of the aforementioned text label. Note that the "true" is a text value and in double-quotes as we are checking the label's text, not for a true/false value in the typical sense. If this count is equal to zero, all of those fields have an entry. If not, one or more is missing an entry.

 

If you did something like :

If(
    CountIf(EquipmentGallery_DetailsScreen.AllItems.lblBlankItems, lblBlankItems.Text = "true") = 0,
    "Save code goes here", 
    UpdateContext({conValidationErr: true, conValidationMessage: "!"})
)

I think you could cut out the entire collection business altogether.

 

Let me know if that works for you or not; I'd be happy to follow up if needed!

View solution in original post

MikeAnderson
Level: Powered On

Re: Checking for empty field values in records in gallery

Beautiful!  That was a brilliant idea and way less clunky than what I had.  Thank you!

Super User
Super User

Re: Checking for empty field values in records in gallery

You are most welcome! Happy to be able to help!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 122 members 5,287 guests
Please welcome our newest community members: