Solved

Can I override role permissions for an Action with code?

  • 25 January 2023
  • 5 replies
  • 82 views

Badge +11

I have a situation where I would like to conditionally allow users to use the ‘Release’ action on Invoices and Memos, even though their role does not permit them to do it normally.

 

I tried action.SetEnabled(true) and action.SetVisible(true) in the RowSelected event, but this is not working.

icon

Best answer by darylbowman 26 January 2023, 18:57

View original

5 replies

Userlevel 7
Badge +5

If the button is still disabled or not visible in spite of your code I’m thinking that Workflow is working against you.  You might have to adjust the workflow built into the form as well.

Userlevel 5
Badge +1

I am not 100% sure but I don’t believe that is possible. It would be easier to allow it for everyone in security and take away the ability programmatically (SetEnabled(false)) instead. 

Badge +11

If the button is still disabled or not visible in spite of your code I’m thinking that Workflow is working against you.  You might have to adjust the workflow built into the form as well.

I don’t think the workflow is the issue, as it is available for those with the permission.

 

I am not 100% sure but I don’t believe that is possible. It would be easier to allow it for everyone in security and take away the ability programmatically (SetEnabled(false)) instead. 

I considered that, but the condition really has nothing to do with permissions, and I’d really rather not have to reimplement the checks they’re doing on role membership. I was hoping for a long-term solution, not quick and dirty.

 

Badge +11

Here’s how I solved this problem:

I created a new action that executes the standard Release action behind the scenes, without regard for the user’s permissions. It is hidden by default.

public PXAction<ARInvoice> customRelease;
[PXButton(CommitChanges = true, IsLockedOnToolbar = true, Connotation = ActionConnotation.Success)]
[PXUIField(DisplayName = "Release", Visible = false)]
protected virtual IEnumerable CustomRelease(PXAdapter adapter)
{
return Base.Release(adapter);
}

In the RowSelected event for the Invoice, I perform my check and instead of attempting to enable the standard Release, I instead show my custom Release, as long as the Invoice has not yet been released AND the standard Release is not already enabled.

customRelease.SetVisible(hasAdjustmentSelected && !isReleaseEnabled && !(invoice.Released ?? false));

Works fancifully.

Userlevel 7
Badge

Thank you for sharing your solution with the community @darylbowman !

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved