Skip to main content
Answer

How do I enable a field when clicking on an action?

  • December 7, 2021
  • 7 replies
  • 633 views

wikusvorster42
Jr Varsity II
Forum|alt.badge.img

The requirement is to enable the Customer Order Nbr when a new action ‘Change Order Nbr’ is selected. I created the below action method. It is executed on clicking the action but the field is not enabled. This is after the invoice was Released. 

public PXAction<ARInvoice> ChangeOrderNbr;
        [PXButton(CommitChanges = true)]
        [PXUIField(DisplayName = "Change Order Nbr", Enabled = false, MapEnableRights = PXCacheRights.Delete, MapViewRights = PXCacheRights.Delete)]
        protected virtual void changeOrderNbr()
        {
            PXUIFieldAttribute.SetEnabled<ARInvoice.invoiceNbr>(base.Base.CurrentDocument.Cache, base.Base.Document.Current, true);

            // Trigger the Save action to save changes in the database.
            // base.Base.Actions.PressSave();
        }

Best answer by Naveen Boga

Hi @wikusvorster42  It is NOT recommended to write the Enable/Disable related code in actions.

It is always recommended to write this kind of logic in Row_Selected event.

 

Coming to your requirement, you can have a Boolean flag, in the Action logic, you can update the flag based on your requirement.

In Row_Selected event, based on this flag is enabled you can enable/disable the respective fields.

7 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • December 7, 2021

Hi @wikusvorster42  It is NOT recommended to write the Enable/Disable related code in actions.

It is always recommended to write this kind of logic in Row_Selected event.

 

Coming to your requirement, you can have a Boolean flag, in the Action logic, you can update the flag based on your requirement.

In Row_Selected event, based on this flag is enabled you can enable/disable the respective fields.


wikusvorster42
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • December 7, 2021

Hi @Naveen B, I did that. Strangely when I do the enable in the Row_Selected it works. When I set a flag and raise event Row_Selected it also doesn’t enable the field.

Just to check, do I do a raise event when calling Row_Selected? That is what I did.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • December 7, 2021

@wikusvorster42  Actually, explicit raise event is not required.

Row_Selected event will raise multiple times at code level and it will taken care of enabling/disabling the fields based on the flags.


wikusvorster42
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • December 7, 2021

Thanks @Naveen B, I will give it a try.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • December 7, 2021

Sure @wikusvorster42  Let me know if any queries.


wikusvorster42
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • December 7, 2021

Hi @Naveen B, it works like a dream. Thank you very much


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • December 7, 2021

@wikusvorster42  Awesome :) Thanks for sharing the update.