Problems with OOTB lookup fields while modifying SharePoint Online list form with PowerApps

 The other day there was a need to create simple automated process for clients management for one of the bank clients.

Solution is pretty much simple - SharePoint Online site with list "Clients" to store all the clients records, library "Documents" to store client's documents in automatically created folders structure and Power Automate flow for the business logic.

According to the business logic some fields must be visible for specific roles only, that is why I decide to go for PowerApps custom list form.

The issue came up once I wanted to put some logic on "Status" field which is SPO drop-down. I needed to have drop-down options to be filtered based on the current value of this drop-down (e.g. if current status is "To Do" so "In progress" and "Reassigned" must be shown, if status is "In progress" - "To be reviewed" and "Reassigned" must be allowed for selection, etc.), but I spent few days to find solution to filter "items" property of the Datacard with no success.

Surfing the Internet I found that this is quite common problem, so the solution to this would be to rework list structure. Thus I recreated "Status" column as simple text field and in PowerApps I just replaced default TextInput control with ComboBox. Drop-down options were created as collection, which was initiated on App.OnStart event. All worked fine.

Next step was to assigned logic. And for this I had to have current value of the field. Instant idea was to have Set(currStatus, StatusField.Selected.Status) assigned to App.OnStart event. But I was surprised to foind out that OnStart even fires earlier than data is populated to the field. So on app load my variable has got nothing in it.

The solution was simple but took me couple of hours to be found. First idea was to have some sort of delay to wait while all the data is loaded to the PowerApp form. But I have not succeed on that.

Finally, I decided to use .Default property of the Datacard (not the control but entire datacard). I did some testing and realized that Datacard.Default is not effected even if the field value is modified. So the final code looks like below:

If(

  IsEmpty(Status_DataCard1.Default) || IsBlank(Status_DataCard1.Default),

  Filter(

    statusesCollect,

    Status = "To Do"

  ),

  If(

    Status_DataCard1.Default = "To Do" || Status_DataCard1.Default = "Reassigned" || Status_DataCard1.Default = "Rejected",

    Filter(

      statusesCollect,

      Status = "In Progress" || Status = "Reassigned"

    ),

    If(

      Status_DataCard1.Default = "In Progress",

      Filter(

        statusesCollect,

        Status = "In Review" || Status = "Reassigned"

      ),

      Filter(

        statusesCollect,

        Status = "Done" || Status = "Rejected" || Status = "Reassigned"

      )

    )

  )

)

This was very interesting and useful experience. Hope this also could be useful for someone else.

Comments