Solved

How can we check button or field enabled or other attributed in code?

  • 11 March 2022
  • 4 replies
  • 98 views

When we want to check button or any field’s UI attribute that is Enabled or not. how can we perform it?

icon

Best answer by yhartman 16 March 2022, 04:03

View original

4 replies

Userlevel 4
Badge

You can try action.GetEnabled().

it’s working with PXAction but for PXUIField it does not work.

Userlevel 4
Badge

I did some research in the source code and it seems you can get a fields attribute in the following way. 

cache.GetAttributesOfType<PXUIFieldAttribute>(null, nameof(field)).FirstOrDefault().Enabled;

I also found an extension that does this for you. However, aside for the extension being there, I have not seen it used anywhere in the source code.

using PX.Objects.CN.Common.Extensions;

bool foo = CacheExtensions.GetEnabled<field>(e.Cache, null);

I hope this helps!

Userlevel 3

Hi @development ,

Can you try the below one to get the Disabled / read-only fields of UI.

 

  #region EventHandler
  protected void DACName_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            var row = (DACName)e.Row;
            if (row != null)
            {

             
                string fieldName = String.Empty;
                foreach (string field in cache.Fields)
                {
                      var state = cache.GetStateExt(null, field) as PXFieldState;
                        if (state != null)
                        {
                            if (!state.Enabled && state.IsReadOnly && state.Visible)
                            {
                              // gettting field Name
                                fieldName = state.Name;
                                
                                // your logic....
                                
                            }
                        }
                }


            }
        }
  #endregion

I hope this helps you.

 

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 — 2020  Acumatica, Inc. All rights reserved