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
Highlighted
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!

3 REPLIES 3
Highlighted
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!

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
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

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