Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Power Fx Patch Status Reason

Like (1) ShareShare
ReportReport
Posted on 27 Jun 2022 08:08:47 by 83

Hello everyone,

 

I am currently trying to change the status and status reason of a data record with a custom command bar button via Power Fx. Changing the status works without problems. However, I cannot change status reason. 

 

Below is my non-working code. Note: I'm German, so I have to use a semicolon instead of a comma and a double semicolon instead of a semicolon (https://docs.microsoft.com/en-us/power-platform/power-fx/expression-grammar#separators).

 

Patch(
 TableName;
 Self.Selected.Item;
 {
 Statusgrund: 'Statusgrund (TableName)'.'Lable of the status reason';
 Status: 'Status (TableName)'.Inaktiv
 }
);;

 

 

After typing Statusgrund: 'Statusgrund (TableName)'. entered, the code completion suggests only the two options Aktiv and Inaktiv. Which leads to the default value of the respective status. Can someone explain me how to use the status reason here? I have already tried to use the value (number) of the status reason: Statusgrund: 'Statusgrund (TableName)'.'4'. I also tried to use the shed and attach the reason: Statusgrund: 'Statusgrund (TableName)'.Inaktiv.'Lable of the status reason'.

 

Thank you and best regards
Nico

  • NoName404 Profile Picture
    on 10 Jun 2024 at 01:02:41
    Re: Power Fx Patch Status Reason

    Old thread but for those that come across this in the future, remember powerlessfx is utter garbage. Best case its barely functional but most of the time you'll have to resort to hacks and workarounds for even the most basic functionality.

    As OP indicates doing something simple as patching the status reason with a custom value requires workarounds because for whatever reason powerlessfx will just not show custom values. Its beyond inane this is required but that is Microsoft for you.

     

    For whoever reads this, do yourself a favor and write a JS function. The JS API is actually solid and much easier to read. I mean honestly? Who thought something like Status: 'Status (Quotes)'.Inactive is even remotely readable? Because logicalfieldname.logicaltablename.value would have been too easy?

  • Verified answer
    HS_Nico Profile Picture
    83 on 27 Jun 2022 at 13:58:18
    Re: Power Fx Patch Status Reason

    I found a solution. ðŸ˜Ž

    You have to create a collection and then use the Index function to select the appropriate value.

    Patch(TableName; Self.Selected.Item; {
     Status: 'Status (TableName)'.Inaktiv;
     Statusgrund: Index(Choices(TableName.Statusgrund); 4).Value
    });;

     

    The only problem is the order. The options are sorted by creation date. In addition, if an option is deleted in the middle, the intex of the following items will be shifted.

  • HS_Nico Profile Picture
    83 on 27 Jun 2022 at 13:54:31
    Re: Power Fx Patch Status Reason

    This is exactly the code I tried first, but it doesn't work for me. Could this have something to do with the fact that we have our environments in different regions?

  • Verified answer
    jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on 27 Jun 2022 at 13:44:51
    Re: Power Fx Patch Status Reason

    buttonInactive.PNG

     

    Hope this helps. In VS Code is the OnSelect of the Status Reason button.

  • HS_Nico Profile Picture
    83 on 27 Jun 2022 at 13:04:41
    Re: Power Fx Patch Status Reason

    Because you do it in a canvas app, that works for me too. However, it does not work with a custom command bar button in a model-driven app.

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on 27 Jun 2022 at 12:59:32
    Re: Power Fx Patch Status Reason

    patchInactive.PNG

    Looking good on my end...

  • HS_Nico Profile Picture
    83 on 27 Jun 2022 at 12:58:59
    Re: Power Fx Patch Status Reason

    Exactly. I'm trying to update an existing record.

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on 27 Jun 2022 at 12:55:47
    Re: Power Fx Patch Status Reason

    You are patching a record that exist already, right?

  • HS_Nico Profile Picture
    83 on 27 Jun 2022 at 12:53:47
    Re: Power Fx Patch Status Reason

    Looks like some problem with the custom command bar button. Because in a canvas app the following code works:

    Patch(TableName; LookUp(TableName; TableName = GUID("6a46bf0a-8617-402a-9023-2d2dea7b80f3")); {
     Status: 'Status (TableName)'.Inaktiv;
     Statusgrund: 'Statusgrund (TableName)'.'4'
    });;

     

    Does anyone know a solution to the problem. Or a workaround?

  • HS_Nico Profile Picture
    83 on 27 Jun 2022 at 12:12:28
    Re: Power Fx Patch Status Reason
    That's the code:

     

    Patch(
     TableName;
     Self.Selected.Item;
     {
     Status: 'Status (TableName)'.Inaktiv;
     Statusgrund: 'Statusgrund (TableName)'.'4'
     }
    );;

     

     
    And these are the error messages:
    • The function 'Patch' has some invalid arguments.
    • The type of this argument 'statuscode' does not match the expected type 'OptionSetValue'. Found type 'Error'.
    • The name is invalid. "4" is not recognized.

    In my opinion the main problem is that I can't reach the inactive status reasons. This means that this Statusgrund: 'Statusgrund (TableName)'.'4' doesn't work even though this Statusgrund: 'Statusgrund (TableName)'.'2' works.

    I also just checked again: both status reasons exist with the respective values. The only difference is that 2 is an active status reason and 4 is an inactive status reason.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard
Loading started
Loading started