0
votes

I'm extending the AccountByPeriodEnq logic, I just want to add a button on top of my screen to modify the selected GL records but it just doesnt want to show up and I can't figure out why.

Here's my code :

namespace PX.Objects.GL
{
    class AccountByPeriodEnqExtensions : PXGraphExtension<AccountByPeriodEnq>
    {
        #region Actions
        public PXAction<AccountByPeriodFilter> Letter;
        [PXUIField(Visible = true, DisplayName = "Lettrer")]
        [PXButton(CommitChanges = true)]
        protected virtual IEnumerable letter(PXAdapter adapter)
        {
            IReadOnlyCollection<GLTranR> selectedTrans = GetSelectedTrans();

            if (selectedTrans.Any())
            {
                PXLongOperation.StartOperation(this, delegate ()
                {
                    foreach(GLTranR line in selectedTrans)
                    {
                        // UpdateSomeFieldsAndPersists
                    }
                });
            }
            else
            {
                throw new PXException("Error");
            }

            return Base.Filter.Select();
        }
        #endregion

        #region Utility
        private IReadOnlyCollection<GLTranR> GetSelectedTrans()
        {
            return Base.GLTranEnq.Cache.Updated
                .Cast<GLTranR>()
                .Where(tran => tran.Selected == true)
                .ToArray();
        }
        #endregion
    }
}

Is there anything I'm missing here ?

Regards,

Edit:

To clarify i'm trying to customize the GL404000, Account Details. And using the inspector I saw the Business logic is in the AccountByPeriodEnq Graph

2
Can you post your screen aspx ? If you customized it you should find it in your website CstPublished folder - Simon ML
I think you might have mismatch the Screen/BLC/DAC name, I'm writing an answer. - Hugues Beauséjour
You should also double check if 'tran.Selected' is giving you the correct reading. I noticed 'Selected' is treated as a special case that doesn't fire events and update cache like other fields. I suspect it's a hardcoded performance hack but can't pinpoint where/why that happens. - Hugues Beauséjour

2 Answers

2
votes

Using Acumatica Inspect Element feature notice that the 'Account by Period' screen (GL402000) is not using the 'AccountByPeriodEnq' graph.

It is using the 'AccountHistoryByYearEnq' graph instead so that's the graph you want to target:

enter image description here

You also need to declare Actions on the primary DAC of that Graph.

The one for 'AccountHistoryByYearEnq' is a little bit harder to find than usual.

You can use Acumatica Source Code page and search for 'PXPrimaryGraph(typeof(AccountHistoryByYearEnq)':

enter image description here

In this case it is AccountByYearFilter DAC that you should use:

[System.SerializableAttribute()]
[PXCacheName(Messages.Account)]
[PXPrimaryGraph(typeof(AccountHistoryByYearEnq), Filter = typeof(AccountByYearFilter))]
public partial class Account : PX.Data.IBqlTable, PX.SM.IIncludable
{
  […]
}

I think this is a special case for Filter, when there's no filter Account would have been the DAC to use for the Actions.


Now that you have identified the Primary Graph of the Screen (AccountHistoryByYearEnq) and the Primary DAC of the Graph (AccountByYearFilter) it should work as expected:

public class AccountByPeriodEnq_Extension : PXGraphExtension<AccountHistoryByYearEnq>
{
  public PXAction<AccountByYearFilter> letter;

  [PXUIField(DisplayName = "Letter")]
  [PXButton]
  protected virtual IEnumerable Letter(PXAdapter adapter)
  {
      return adapter.Get();
  }
}

UI: enter image description here


EDIT:

For Account detail page (GL404000), use the same code with different DAC and Graph:

using PX.Data;
using System.Collections;

namespace PX.Objects.GL
{
  public class AccountByPeriodEnq_Extension : PXGraphExtension<AccountByPeriodEnq>
  {
      #region Actions
      public PXAction<AccountByPeriodFilter> letter;

      [PXUIField(DisplayName = "Letter")]
      [PXButton]
      protected virtual IEnumerable Letter(PXAdapter adapter)
      {
          return adapter.Get();
      }
      #endregion
  }
}

With a base Acumatica install that's all that is needed for the Action to appear: enter image description here

Note that you can specify explicit state and view rights for the button control, though I don't think your issue is related to access rights if you're working in a developer instance:

[PXUIField(DisplayName = "Letter", 
           MapEnableRights = PXCacheRights.Select, 
           MapViewRights = PXCacheRights.Select)]
0
votes

I finally found my problem, I missed the public member for my class.

namespace PX.Objects.GL
{
    public class AccountByPeriodEnqExtensions : PXGraphExtension<AccountByPeriodEnq>
    {
        #region Actions
        public PXAction<AccountByPeriodFilter> Letter;

Thanks for your answer HB, i'll reuse it.