Solved

Need to load data from smart panel to a grid

  • 21 February 2023
  • 5 replies
  • 311 views

Userlevel 3
Badge

Hi,

I have added a smart panel to my customized screen. When the customer is selected in the from and clicked on the “Add Purchase” button, all the purchase orders get loaded into the smart panel. Below screenshots for the reference.

 

Now I need to add selected purchase orders into my customized grid below the form. But my issue is, when I select orders and clicked on “Add & close”, still the grid is empty. Can someone help me with this issue please?

Thank you in advance.

Below is the code for my action, defined in the graph extension which is created when adding the smart panel

 

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

public virtual IEnumerable myAction(PXAdapter adapter)
{


if (POrdersView.AskExt() == WebDialogResult.OK)
{
APProformaItemList proforma = Base.APProformaItems.Current;
proforma.LineNbr = 1;
Base.APProformaItems.Update(proforma);
Base.Save.Press();


}
return adapter.Get();



}

For the reference:

APProforma = DAC for the form of the screen (parent DAC)

APProformaItemList : DAC for the grid

APProformaItems : View for the grid

POrdersView : view for the smart panel (POOrder DAC)

 

 

icon

Best answer by Dioris Aguilar 21 February 2023, 16:20

View original

5 replies

Userlevel 5
Badge +2

@oshadarodrigo64 The reason the grid is empty is because the selected line from the smartpanel is not being inserted into the Proforma Invoice screen. Please, take a look at the AddInvBySite method in SOOrderEntry for a complete working reference on how this should be done. Basically, you need to do something like this:

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

public virtual IEnumerable myAction(PXAdapter adapter)
{


if (POrdersView.AskExt() == WebDialogResult.OK)
{
return InsertSelectedLines(adapter);


}
return adapter.Get();



}

And then, the InsertSelectedLines() method should be defined like this:

public virtual IEnumerable InsertSelectedLines(PXAdapter adapter){
foreach(PopupWindowDAC line in smartPanelGridView.Cache.Cached){
if(line.Selected == false) continue;
DestinyToInsertDAC toBeInserted = PXCache<DestinyToInsertDAC>.CreateCopy(DestinyDetailView.Insert(new DestinyToInsertDAC()));
//Fill fields values
...
toBeInserted = PXCache<DestinyToInsertDAC>.CreateCopy(DestinyDetailView.Update(toBeInserted));
//Other fields assignment
DestinyDetailView.Update(toBeInserted);
}
return adapter.Get();
}


In your case:

POOrder = PopupWindowDAC

APProformaItems = DestinyDetailView

APProformaItemList = DestinyToInsertDAC

Userlevel 3
Badge

Hi @Dioris Aguilar ,Thank you so much for the response with clear guidance, It’s really helpful to get it solved.

 

Userlevel 3
Badge

Hi @Dioris Aguilar,

I tried your solution and now I’m able to add one selected item into the grid. But when I’m going to add more than one items(multiple items), it gives me the below error. And also after adding and saved selected item, same error happens.

 

Below is the code for the method.

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


if (POrdersView.AskExt() == WebDialogResult.OK)
{

return InsertSelectedLines(adapter);


}
return adapter.Get();



}

public virtual IEnumerable InsertSelectedLines(PXAdapter adapter)
{
foreach (POOrder line in POrdersView.Cache.Cached)
{
if (line.Selected == false) continue;

APProformaItemList toBeInserted = PXCache<APProformaItemList>.CreateCopy(APProformaView.Insert(new APProformaItemList()));

toBeInserted.Ponbr = line.OrderNbr;
toBeInserted.LineNbr = 1;
toBeInserted.POLineNbr = 1;
toBeInserted.POrderQty = 30;
toBeInserted.Itemid = 25;

toBeInserted = PXCache<APProformaItemList>.CreateCopy(APProformaView.Update(toBeInserted));
APProformaView.Update(toBeInserted);


}
return adapter.Get();

}

Have I missed something in the code? Can You help me with this please?

Thank you.

Userlevel 5
Badge +2

Hi @oshadarodrigo64 ,

Place a break point and debug your code, the Move Next error you are getting seems to be a null reference somewhere.

Userlevel 3
Badge

Hi,

sorry for being late to reply,

I tried debugging using break points but couldn’t see any issues there. Is there any other way to get into the solution?

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