Solved

Want to add data from Smart Panel

  • 21 February 2023
  • 4 replies
  • 241 views

Userlevel 3
Badge

Hi,

I added a smart panel for my customized screen. After the customer select, all the purchase order show in smart panel like below.

After I clicked the checkbox and clicked ADD button clicked line need to be add to the grid view Below like that.

But,My issue is when I clicked the add button data is not added to grid.

This is my Action method.

 

 public PXAction<APProforma> addNewOrder;
        [PXButton(CommitChanges = true, DisplayOnMainToolbar = false)]
        [PXUIField(DisplayName = "", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = false)]


        protected virtual IEnumerable AddNewOrder(PXAdapter adapter)
        {
            APProformaView.AllowInsert = true;
            PXSelectBase<POOrder> orders =
                    new PXSelect<POOrder,
                    Where<POOrder.orderNbr, Equal<Current<APProformaItemList.ponbr>>>>(Base);

            

            foreach (POOrder item in orders.Select())
            {
                
                APProformaItemList newOrder = new APProformaItemList();
                newOrder = APProformaView.Insert(newOrder);
                newOrder.Ponbr = item.OrderNbr;
                newOrder.POLineNbr = 5;
                newOrder.ProFormaQty = 100;
                newOrder.Itemid = 1;
                newOrder.POrderQty = 25;
                APProformaView.Update(newOrder);

            }

            return adapter.Get();

        }

 

For your reference:
APProforma = Parent DAC (customized form)
APProformaItemList = DAC for the grid in the tab
APProformaEntry = screen graph

Can you please help me for the issue.

Thanks you

icon

Best answer by Django 21 February 2023, 16:24

View original

4 replies

Userlevel 7
Badge +5

I think (and I’m happy to be corrected) that when you’re using PXAction with IEnumerable that your asking Acumatica to do your processing in another thread so the user can see the “Please Wait” box.

Because of this, you want to make a separate graph to do your processing, save the changes and then return the Adapter which will refresh your screen.

Here is an example of an action button that I’ve added to SOOrderEntry.  It works for what I need it to do at the moment - in the future I’ll update it to allow it to be called by a processing screen.

public PXAction<SOOrder> MyCustomButtonAction;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Create Jobs", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = true)]
protected virtual IEnumerable myCustomButtonAction(PXAdapter adapter)
{

Base.Actions.PressSave();

var doc = Base.Document.Current;
var orderType = doc.OrderType;
var orderNbr = doc.OrderNbr;

PXLongOperation.StartOperation(Base, ()=> {
var orderGraph = PXGraph.CreateInstance<SOOrderEntry>();
orderGraph.Document.Current = SOOrder.PK.Find(orderGraph, orderType, orderNbr);
DoTheGoodStuff(orderGraph);
});

return adapter.Get();

}

private static void DoTheGoodStuff(SOOrderEntry soOrderEntry)
{

//in here I have the SOOrderEntry graph with the record loaded.
//I do whatever I need
//and then make sure to call

soOrderEntry.Save.Press();

}

So I think that part of your issue is that you’re not saving the transaction (persisting).

Userlevel 3
Badge

Hi @Django ,

Thank you for your quick response.

But,I didn’t get you point clearly.

We create a graph extension for the smart panel section.I added full code for your refernce.

APProformaEntry is our main screen graph.

 

using PX.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PX.Data.BQL.Fluent;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.PO;
using System.Collections;


namespace GRIProformaInvoice.Extension
{
       public class APProformaEntry_Extension : PXGraphExtension<APProformaEntry>
    {

        public SelectFrom<POOrder>.View POrdersView; //view for the smart panel

        public SelectFrom<APProformaItemList>.View APProformaView;  //view for the grid

        public PXAction<APProforma> MyAction;
        [PXUIField(DisplayName = "Add Purchase", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXButton(CommitChanges = true)]
        public virtual IEnumerable myAction(PXAdapter adapter)
        {

            POrdersView.AskExt();
            return adapter.Get();

        }

        public PXAction<APProforma> addNewOrder;
        [PXButton(CommitChanges = true, DisplayOnMainToolbar = false)]
        [PXUIField(DisplayName = "", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = false)]


        protected virtual IEnumerable AddNewOrder(PXAdapter adapter)
        {
            APProformaView.AllowInsert = true;
            PXSelectBase<POOrder> orders =
                    new PXSelect<POOrder,
                    Where<POOrder.orderNbr, Equal<Current<APProformaItemList.ponbr>>>>(Base);

            

            foreach (POOrder item in orders.Select())
            {
                
                APProformaItemList newOrder = new APProformaItemList();
                newOrder = APProformaView.Insert(newOrder);
                newOrder.Ponbr = item.OrderNbr;
                newOrder.POLineNbr = 5;
                newOrder.ProFormaQty = 100;
                newOrder.Itemid = 1;
                newOrder.POrderQty = 25;
                APProformaView.Update(newOrder);

            }

            return adapter.Get();

        }
     }
}

 

We added to actions in here

  1. Add Purchase - to the load smart panel
  2. addNewOrder - to add the purchase order details to my main screen grid from the smart panel

Can you please check and give a solution for that.

Thanks you

Userlevel 7
Badge +5

When you debug your code in AddNewOrder, is orders.Select() returning rows?

If it is, before you call return adapter.Get(), can you add: APProformaEntry.Save.Press();

What I think is happening is that you’re updating the transaction that’s visible on the screen but not saving it and then the return adapter.Get() is making the screen refresh the transaction and it re-loads the original values from the database.

Userlevel 7
Badge +5

Someone else is working on this exact project it would seem - have a look at that threat as there is some more detailed code examples.

 

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