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
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?
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.
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?
Hope this helps. In VS Code is the OnSelect of the Status Reason button.
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.
Looking good on my end...
Exactly. I'm trying to update an existing record.
You are patching a record that exist already, right?
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?
Patch(
TableName;
Self.Selected.Item;
{
Status: 'Status (TableName)'.Inaktiv;
Statusgrund: 'Statusgrund (TableName)'.'4'
}
);;
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.
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,079
Most Valuable Professional