cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HS_Nico
Helper I
Helper I

Power Fx Patch Status Reason

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
jcfDaniel
Impactful Individual
Impactful Individual

buttonInactive.PNG

 

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

View solution in original post

HS_Nico
Helper I
Helper I

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.

View solution in original post

18 REPLIES 18
jcfDaniel
Impactful Individual
Impactful Individual

Hi,

 

Status Reason have a related Status, so you cannot have a Status of Active and a Status Reason of Inactive (I mean by default since you can change the default Status Reason).

 

Try changing first the Status and then the Status Reason.

Unfortunately that doesn't work either. Even if the status reason belongs to the current status.

I am unable to change the status reason using patch.

jcfDaniel
Impactful Individual
Impactful Individual

Have you enabled status reason transitions?

HS_Nico
Helper I
Helper I

Okay, the problem is getting pretty confusing.

 

I am able to change the active status reasons. It doesn't matter whether the current status is active or inactive. And I can change the status to inactive. But what doesn't work is to set one of the inactive status reasons. It doesn't matter whether the status is already inactive or not.

 

That works

 

Patch(
    TableName;
    Self.Selected.Item;
    {
        Status: 'Status (TableName)'.Aktiv;
        Statusgrund: 'Statusgrund (TableName)'.'2'
    }
);;

 

 

That works too

 

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

 

 

That doesn't work

 

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

 

 

jcfDaniel
Impactful Individual
Impactful Individual

Statusgrund 4 is an Inactive Status?

 

status.PNG

Yes, exactly. Status Reasons 1 and 2 are Active Statuses and 3 through 6 are Inactive Statuses. An error (underlined in red) is only displayed in the code for the inactive status.

jcfDaniel
Impactful Individual
Impactful Individual

and when you patch no error is returned? Are you sure you have no statuses transitions setup?

I just checked again: status reason transitions are disabled.

 

When I press the created button in the model-driven app, I get an error message. But it doesn't contain a lot of information. Only the error code "0x0", the session id, the activity id and the time.

jcfDaniel
Impactful Individual
Impactful Individual

When you hover through that red underline, there should be an indication of whats wrong. What does it read?

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,749)