Skip to main content
Solved

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


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

Best answer by yhartman

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!

View original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+3
  • Jr Varsity I
  • 62 replies
  • March 11, 2022

You can try action.GetEnabled().


  • Author
  • Freshman I
  • 3 replies
  • March 15, 2022

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


Forum|alt.badge.img+3
  • Jr Varsity I
  • 62 replies
  • Answer
  • March 16, 2022

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!


Forum|alt.badge.img+1

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings