Thanks.I have set SyncPosition as true and the Smart Panel’s AutoCallBack enabled. Below is the code that i am using for the popup panel.
public PXAction<CWSyncInvoiceLine> ViewInvProdDetails;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Import Product")]
protected virtual IEnumerable viewInvProdDetails(PXAdapter adapter)
{
var row = CWSyncInvDetails.Current;
if (row == null)
return adapter.Get();
List<ProductCatalog> items = Service.GetProduct().Result;
var item = items.Where(x => x.identifier == row?.ProductID).FirstOrDefault();
ProductPanelView.Cache.Clear();
if (item == null) return adapter.Get();
var panel = new CWProductPanel
{
ProductID = item?.id,
Identifier = item?.identifier,
Description = item?.description,
ItemType = "NONSTOCK",//default
Type = item.type?.name,
ProductClass = item?.productClass,
};
ProductPanelView.Insert(panel);
if (ProductPanelView.AskExt() == WebDialogResult.OK)
{
string type = ProductPanelView.Current?.ItemType;
if (string.IsNullOrEmpty(type))
throw new PXException(Messages.stockOrNonstock);
if (type == "STOCK")
{
// Create item and return graph
InventoryItemMaint itemGraph = CreateInventoryItem(ProductPanelView.Current);
// Redirect to the new item
throw new PXRedirectRequiredException(itemGraph, "Stock Item")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
}
}
return adapter.Get();
}
This looks like I was asking for. When you do the ask by this line:
if (ProductPanelView.AskExt() == WebDialogResult.OK)
popup is coming up. Then you click Ok on the popup. What does happen on the code side at that point? It starts working from the beginning. That means it goes to
ProductPanelView.Cache.Clear();
if (item == null) return adapter.Get();
var panel = new CWProductPanel
{
ProductID = item?.id,
Identifier = item?.identifier,
Description = item?.description,
ItemType = "NONSTOCK",//default
Type = item.type?.name,
ProductClass = item?.productClass,
};
ProductPanelView.Insert(panel);
and all of your previous data is being removed on this point. I recommend you to check if there is already an answer to the ask and if there is no answer then do the clearing and creating.
if (ProductPanelView.View.Answer != WebDialogResult.OK)
{
List<ProductCatalog> items = Service.GetProduct().Result;
var item = items.Where(x => x.identifier == row?.ProductID).FirstOrDefault();
ProductPanelView.Cache.Clear();
if (item == null) return adapter.Get();
var panel = new CWProductPanel
{
ProductID = item?.id,
Identifier = item?.identifier,
Description = item?.description,
ItemType = "NONSTOCK",//default
Type = item.type?.name,
ProductClass = item?.productClass,
};
ProductPanelView.Insert(panel);
}
something like this should make it work