Skip to main content
Solved

Need to load data from smart panel to a grid


Forum|alt.badge.img

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)

 

 

Best answer by Dioris Aguilar

@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

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

5 replies

Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+2
  • Jr Varsity I
  • 91 replies
  • Answer
  • February 21, 2023

@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


Forum|alt.badge.img

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

 


Forum|alt.badge.img

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.


Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+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.


Forum|alt.badge.img

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


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