acumaticaacumatica-kb

Dialog box for new action on SO301000 screen, cannot add more than one item to the grid


I am trying to add a dialog box to the SO301000 screen, this dialog box (I think its also considered a smart panel but the difference is lost on me) is just supposed to show a list of orders that a customer has made.

What I have working:

1: I am able to pull all of the orders that a customer has made.

2: I am able to open/close the dialog box after clicking the action.

3: An order IS able to be put into grid.

What doesn't work:

1: I am unable to get more than one order into the grid.

I have no need to edit the orders in this grid, I just want to puke out quick information.

 public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {

        public PXFilter<MSCustomerOrderDac> MSCustomerViewForm;
        public PXFilter<MSCustomerOrderDac> MSCustomerOrderViews; //Issue.


        public PXAction<SOOrder> ViewCustomerOrders;
        [PXUIField(DisplayName = "View Custoemr", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXButton(Category = "Other")]
        [PXUIEnabled(typeof(Where<SOOrder.customerID.IsNotNull>))]
        protected virtual IEnumerable viewCustomerOrders(PXAdapter adapter)
        {
            MSCustomerOrderViews.AllowInsert=true;

            PXSelectBase<SOOrder> orders =
                    new PXSelectReadonly<SOOrder,
                    Where<SOOrder.customerID, Equal<Current<SOOrder.customerID>>>>(Base);
            int linenumber = 0;

             foreach (SOOrder order in orders.Select())
             {
                MSCustomerOrderDac newOrder = new MSCustomerOrderDac();
                newOrder.OrderNumber = order.OrderNbr;
                newOrder.LineNbr = linenumber++;
                newOrder = MSCustomerOrderViews.Insert(newOrder);

             }

            if (MSCustomerViewForm.AskExt(true) != WebDialogResult.OK) //need this to show the form
            {}
            
            return adapter.Get();
        }

        [PXVirtual]
        [Serializable]
        public class MSCustomerOrderDac : IBqlTable
        {

            #region OrderNumber 
            [PXString]
            [PXUIField(DisplayName = "Order Number")]
            public virtual String OrderNumber { get; set; }
            public abstract class orderNumber  : PX.Data.BQL.BqlString.Field<orderNumber> { }
            #endregion

            [PXInt(IsKey = true)]
            public virtual Int32? LineNbr { get; set; }
            public abstract class lineNbr : PX.Data.BQL.BqlInt.Field<lineNbr> { }



        }
    }

This is the whole of my code, I also tried breaking the loop and adding more than 1 items manually but that made no difference.

I also found this thread on the community forums: https://community.acumatica.com/customizations-187/dialog-with-grid-with-in-memory-dac-from-action-button-8578

However I think he and I were having different issues.

Also, I have just noticed that the order that it is pushing is aways the same one.


Solution

  • The following code snippits will give you the desired functionality.

    Create a graph extension that has an declared data view that will retrieve the information desired, in this case SOOrders related to the Customer.

    public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
    {
        [PXFilterable]
        [PXCopyPasteHiddenView]
        public PXSelectReadonly<SOOrder2, Where<SOOrder2.customerID, Equal<Current<SOOrder.customerID>>>> RelatedOrders;
    
        public PXAction<SOOrder> ViewCustomerOrders;
        [PXUIField(DisplayName = "View Customer Orders", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
        [PXButton]
        protected virtual void viewCustomerOrders()
        {
                 RelatedOrders.AskExt(true);
        }
    
        protected virtual void __(Events.RowSelected<SOOrder> e)
        {
            if(e.Row is SOOrder row)
            {
                ViewCustomerOrders.SetVisible(true);
                ViewCustomerOrders.SetEnabled(true);
            }
        }
    }
    

    If multiple views are declared on a graph / extension that utilize the same DAC issues may occur. To overcome this issue a derived DAC needs to be created [SOOrder2] with the key / search criteria fields redeclared which will allow the framework to properly segregate the cache types.

    [Serializable]
    [PXHidden]
    public class SOOrder2 : SOOrder
    {
        #region DocType
        public new abstract class orderType : BqlString.Field<orderType>
        {
        }
        #endregion
    
        #region RefNbr
        public new abstract class orderNbr : BqlString.Field<orderNbr>
        {
        }
        #endregion
    
        #region CustomerID
        public new abstract class customerID : BqlInt.Field<customerID>
        {
        }
        #endregion
    }
    

    The smart panel that your view utilizes can be found below :

    <px:PXSmartPanel runat="server" ID="CustomerRelatedOrderPnl" Height="550px" Width="950px" CaptionVisible="True" Caption="Related Orders" Key="RelatedOrders" AutoCallBack-Target="CustomerRelatedOrderGrid" AutoCallBack-Command="Refresh">
        <px:PXGrid runat="server" ID="CustomerRelatedOrderGrid" SyncPosition="True" Height="100%" SkinID="Inquire" Width="100%" DataSourceID="ds" NoteIndicator="False">
            <AutoSize Enabled="True" />
            <Levels>
                <px:PXGridLevel DataMember="RelatedOrders">
                    <Columns>
                        <px:PXGridColumn DataField="OrderType" Width="140" />
                        <px:PXGridColumn DataField="OrderNbr" Width="140" />
                        <px:PXGridColumn DataField="CustomerID" Width="140" />
                        <px:PXGridColumn DataField="Status" Width="140" />
                        <px:PXGridColumn DataField="OrderDate" Width="140" />
                        <px:PXGridColumn DataField="CuryOrderTotal" Width="140" />
                    </Columns>
                </px:PXGridLevel>
            </Levels>
        </px:PXGrid>
        <px:PXPanel runat="server" ID="CustomerRelatedOrderButtonPnl">
            <px:PXButton runat="server" DialogResult="OK" Text="Ok" CommandSourceID="ds" ID="CustomerRelatedOrderOK" />
        </px:PXPanel>
    </px:PXSmartPanel>
    

    The results of this code can be seen here :

    RelatedOrdersPopUp