Solved

Is there a way to conditionally hide a button in a dialog?

  • 25 February 2022
  • 10 replies
  • 501 views

Userlevel 5
Badge +1

We would like to hide the AUTHORIZE button in the dialog for Create Payment on Sales Order Entry.  The button should be disabled/hidden if Payment Method ID = “CCARD” 

 

Is this something that is possible to do?

 

I have the code to check the payment method but I’m not sure how or even if it’s possible to hide the AUTHORIZE button when the field is updated.

 

Thanks for any advice even if it’s just that it’s not possible to do what we want.

 

Phil 

icon

Best answer by Nayan Mansinha 2 March 2022, 23:56

View original

10 replies

Badge +11

I’m not sure if it’s possible or not, but one alternative could be duplicating the dialog and removing the button from one, so that you have two different versions of the same dialog. If you override where the dialog is called from, you could decide which dialog to show depending on which payment method is used.

Edit:

Just realized I don’t think you have that information prior to the dialog being called, in which case, this wouldn’t work.

(I’d delete this post, but I don’t think that’s possible.)

Userlevel 7
Badge

Hi @Deetz no worries, it’s your effort to help that’s appreciated! Anyone have any other ideas for @ppowell ? Thank you!

Userlevel 5
Badge +1

Failing being able to hide the button is it possible to just pop up a warning message and ignore the button press if the payment method is CCARD? I’ve been looking at the source for SOOrderEntry but can’t seem to find where this is triggered.

Userlevel 7
Badge +5

The button is a Dialog within the SO301000 screen. I invoked the screen and then used Ctrl+Alt to click on the Authorize button so I could add the screen to a customization project and find the button faster.

Looking at the properties of the button I see that it is calling a command called CreatePaymentAuthorize.  I searched through the codebase and found that action declared in CreatePaymentExtBase.cs which is a graph extension.
 

public PXAction<TDocument> createPaymentAuthorize;
[PXUIField(DisplayName = "Authorize", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton(DisplayOnMainToolbar = false)]
protected virtual IEnumerable CreatePaymentAuthorize(PXAdapter adapter)
{
AssignAuthorize();

return adapter.Get();
}

Now, at this point, I’ve hit the end of my knowledge because I don’t understand how this graph extension is being instantiated so I’m not sure how to write the extension to wrap around it.

Hopefully someone can expand upon that to get you further.

Badge +11

With that knowledge, couldn’t you do a 

createPaymentAuthorize.SetEnabled(false);

somewhere?

Userlevel 5
Badge +1

With that knowledge, couldn’t you do a 

createPaymentAuthorize.SetEnabled(false);

somewhere?

Thanks.  I’ll try it and see what I can come up with.

Userlevel 4
Badge +2

With that knowledge, couldn’t you do a 

createPaymentAuthorize.SetEnabled(false);

somewhere?

That somewhere will be in the RowSelected event of the DAC that displays Create Payment dialog.  See example  code below:

using PX.Data;
using PX.Objects.SO.GraphExtensions.SOOrderEntryExt;

namespace PX.Objects.SO
{
public class SOOrderEntry_Extension : PXGraphExtension<CreatePaymentExt, SOOrderEntry>
{
public static bool IsActive() => true;

#region Event Handlers

protected virtual void _(Events.RowSelected<SOQuickPayment> eventArgs, PXRowSelected baseEvent)
{
baseEvent?.Invoke(eventArgs.Cache, eventArgs.Args);

// control buttons here
Base1.createPaymentAuthorize.SetVisible(
eventArgs.Row.PaymentMethodID != "CCARD");
}

#endregion
}
}

 

Userlevel 5
Badge +1

With that knowledge, couldn’t you do a 

createPaymentAuthorize.SetEnabled(false);

somewhere?

That somewhere will be in the RowSelected event of the DAC that displays Create Payment dialog.  See example  code below:

using PX.Data;
using PX.Objects.SO.GraphExtensions.SOOrderEntryExt;

namespace PX.Objects.SO
{
public class SOOrderEntry_Extension : PXGraphExtension<CreatePaymentExt, SOOrderEntry>
{
public static bool IsActive() => true;

#region Event Handlers

protected virtual void _(Events.RowSelected<SOQuickPayment> eventArgs, PXRowSelected baseEvent)
{
baseEvent?.Invoke(eventArgs.Cache, eventArgs.Args);

// control buttons here
Base1.createPaymentAuthorize.SetVisible(
eventArgs.Row.PaymentMethodID != "CCARD");
}

#endregion
}
}

 

Thanks.  I just tested and it appears to do exactly what we wanted.  I really appreciate your help,

 

Phil

Badge +11

@nmansinha 

If I may ask, what is the difference between

protected virtual void _(Events.RowSelected<SOQuickPayment> eventArgs, PXRowSelected baseEvent) { }

and

protected virtual void _(Events.RowSelected<SOQuickPayment> eventArgs) { }

 

I see you’re invoking a base event of some sort. Is this necessary? I haven’t seen that around much.

Userlevel 4
Badge +2

@nmansinha

If I may ask, what is the difference between

protected virtual void _(Events.RowSelected<SOQuickPayment> eventArgs, PXRowSelected baseEvent) { }

and

protected virtual void _(Events.RowSelected<SOQuickPayment> eventArgs) { }

 

First one allows to override the base event, and the other one hooks up(creates) an event.  Learn more about it here: Acumatica

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