Forum Discussion

Acorn999's avatar
Acorn999
Brass Contributor
Jul 13, 2023

If(Not(IsBlank([DataCardValue]) is always returning true in cases where it should not

I have a Power Apps Canvas app with a tab-like experience developed. The tabs are created from a gallery of buttons. There are fields on each tab. 

 

If a tab is selected, the tab fill should be blue.

Else if the tab is not selected and a specific field on tab 2 (DataCardValue14) has a value, the tab fill should be green to show the field has a value. Else if the tab is not selected and the specific field (DataCardValue14) does NOT have a value, the tab fill should be grey.

 

The idea is to provide an easy way for users to know if a given tab has an entry for the field or not by seeing the tab color is green, without having to go check it on each tab. Once this works I will add additional fields so the user will know by color if the tab has all the fields entered or not. But for now I am focused on the color fill for one field. 

 

See the screenshot.

 

The issue:

The code I have written below will:

1] Successfully set the tab fill to blue if the tab is selected

2] Issue here: If the tab is not selected, PA sets the fill to green whether or not the DataCardValue14 field has a value. PA always responds as if this field has a value, even if it does not value. The result is the tab fill is always green even in cases where it should be grey (field is blank).

 

These have all been tried independently in the Gallery Fill property and all show the same issue.

RGBA(0, 120, 212, 1) is the blue color for a selected tab. I have excluded the code that sets the color on a specific tab for clarity. At this point I just need the code below to accurately see if the DatacardValue is blank or not.

 

I have tried this with other fields, the same issue replicates on any field. The backend is a SharePoint List. DataCardValue14 refers to a single line of text field, and entry is not required.

 

If(varTabSelected = ThisItem.ID, RGBA(0, 120, 212, 1),If(Not(IsBlank([DataCardValue14])), Color.Green, Color.Gray))


If(varTabSelected = ThisItem.ID, RGBA(0, 120, 212, 1),If(Not(IsBlank([DataCardValue14.Text])), Color.Green, Color.Gray))


If(varTabSelected = ThisItem.ID, RGBA(0, 120, 212, 1),If(Not(IsEmpty([DataCardValue14])), Color.Green, Color.Gray))


If(varTabSelected = ThisItem.ID, RGBA(0, 120, 212, 1),If(Not(IsEmpty([DataCardValue14.Text])), Color.Green, Color.Gray))

  • I started a new issue titled: Incompatible types for comparison. These types can't be compared: Table, Number. Setting this update as the best response on this issue so the issue won't have duplicate tickets.
  • H2O's avatar
    H2O
    Iron Contributor

    Acorn999 

    The issue you are experiencing is that the If Not IsBlank function is always returning true even when the DataCardValue is blank. This is because the IsBlank function only checks if the value of the DataCardValue is empty, not if it is visible. In your case, the DataCardValue is visible, but it is empty.

    There are a few ways to fix this issue. One way is to use the HasValue function instead of the IsBlank function. The HasValue function will check if the DataCardValue has any value, regardless of whether it is empty or not.

    Another way to fix this issue is to use the Visible property of the DataCardValue. If the DataCardValue is visible, but it is empty, then you can set the Visible property to false. This will hide the DataCardValue, and the If Not IsBlank function will no longer return true.

    Here is an example of how to fix this issue using the HasValue function:

    If HasValue(DataCardValue1) Then
        // Do something
    Else
        // Do something else
    End If

    Here is an example of how to fix this issue using the Visible property:

    If DataCardValue1.Visible Then
        // Do something
    Else
        // Do something else
    End If

    I hope this helps.

    • Acorn999's avatar
      Acorn999
      Brass Contributor

      H2O 

       

      Very Appreciated for your help. Both of your solutions were not successful.

       

      1. HasValue() is not a known function in MS PowerApps. It looks like it is related to checking whether a Media data type field in a record has been initialized with a media object and that the object exists - for Dynamics NAV.

      2. Whether the field is visible or not: What causes certain fields to only show when a given tab is selected is the Visible property. This is what makes the tabbed form work as a tabbed form. Normally I set the Visible Property to:

       

      varTabSelected=2

       

      So that it only shows when tab 2 is selected.

      In response to your suggestion,

      I can't set the Visible Property to false if the field is blank because I have no working function to know of the field is blank - that's my issue, ,Not(isBlank is always returning true, and I need the Visible Property to show the field only if the associated tab is selected, whether or not the field is blank. 

       

      However, to test if the visible property is having an effect or causing this issue, I set the Visible property to true so the field always shows regardless of which tab is selected. In this scenario, the issue persists. 

  • Acorn999's avatar
    Acorn999
    Brass Contributor
    I have made an additional discovery on this issue but not yet identified a resolution:

    If the Visible Property is set to true so the field always shows
    and the Gallery Fill property is set so that the field having a value is the only condition:
    If(Not(IsBlank([DataCardValue14.Text])), Color.Green, Color.Gray)

    the issue persists.

    I tried setting the default value to 5, and then setting the Gallery Fill property to this:
    If([DataCardValue14] = 5, Color.Green, Color.Gray)

    This did not work but it did provide information about the issue:
    Power Apps shows "Incompatible types for comparison. These types can't be compared: Table, Number."

    So assuming 5 is the number, it looks like PowerApps sees DataCardValue14 is a table.
    In the backend SharePoint, DataCardValue14 is a Single Line of Text field with no validations and it is not required. I do not know why PowerApps sees this field as a table. I have not found anything useful so far Googling the issue.

    • Acorn999's avatar
      Acorn999
      Brass Contributor
      I started a new issue titled: Incompatible types for comparison. These types can't be compared: Table, Number. Setting this update as the best response on this issue so the issue won't have duplicate tickets.
  • TejpalBisht's avatar
    TejpalBisht
    Copper Contributor

    Try this 

     

     

    If(DataCardValue1.Selected.Value=Blank(),1,2)

     

    • DataCardValue1.Selected.Value: This refers to the value selected in a data card control named "DataCardValue1". Data cards are used to display and edit data in a form.
    • Blank(): This is a function that checks if a value is empty or null.
    • If(condition, value_if_true, value_if_false): This is the If function in Power Apps. It evaluates the condition and returns the value_if_true if the condition is true, and the value_if_false if the condition is false.

    So, in this case, the If statement is checking if the selected value in DataCardValue1 is empty. If it is empty, the function will return 1. Otherwise, if the selected value is not empty, it will return 2.

    This function can be used to perform different actions or calculations based on whether a specific data card value is empty or not.

    Acorn999 

Resources