Skip to main content
Answer

Can I override role permissions for an Action with code?

  • January 25, 2023
  • 5 replies
  • 150 views

darylbowman
Captain II
Forum|alt.badge.img+15

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.

Best answer by darylbowman

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.

5 replies

Forum|alt.badge.img+7
  • Captain II
  • January 25, 2023

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.


Shawn Burt
Jr Varsity I
Forum|alt.badge.img+1
  • Jr Varsity I
  • January 25, 2023

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. 


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • January 25, 2023

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.

 


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • Answer
  • January 26, 2023

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.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • January 27, 2023

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