Why won't my PXSmartPanel display the correct data after the first execution?

人走茶凉 提交于 2021-02-07 10:45:48

问题


I am using a PXSmartPanel to display data from the current row and allow the user to make a choice before manipulating that data.

The first execution works flawlessly. However, subsequent executions display the first execution's data. I don't think it's code related, but here's the dialog call:

    public PXAction<MXBatch> moveToQueue;
    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "MoveToQueue")]
    protected virtual void MoveToQueue()
    {
        MXBatch selectedBatch = Batches.Current;
        if (selectedBatch == null) return;

        // Select batch and check for existing mixes
        var batchGraph = PXGraph.CreateInstance<MXBatchEntry>();
        batchGraph.Document.Current = batchGraph.Document.Search<MXBatch.batchID>(selectedBatch.BatchID);

        if (batchGraph.Transactions.Select().Count > 0)
        {
            Batches.Ask("Already Converted", "This batch already has at least one mix associated with it. This action will be cancelled.", MessageButtons.OK, MessageIcon.Error);
            return;
        }

        var soGraph = PXGraph.CreateInstance<SOOrderEntry>();
        soGraph.Document.Search<SOOrder.orderType, SOOrder.orderNbr>(selectedBatch.SOOrderType, selectedBatch.SOOrderNbr);
        SOLine soLine = soGraph.Transactions.Search<SOLine.lineNbr>(selectedBatch.SOLineNbr);

        // Check if Sales Order line exists
        if (soLine == null) Batches.Ask("Missing Sales Order", "The Sales Order item associated with this mix cannot be found. This action will be cancelled.", MessageButtons.OK, MessageIcon.Error);

        // Calculate the current batch weight in CWT
        decimal batchWt = 0m;
        batchWt = INUnitAttribute.ConvertFromTo<SOLine.inventoryID>(soGraph.Transactions.Cache, soLine, soLine.UOM, setup.Current.CwtUOM, soLine.Qty ?? 0, INPrecision.QUANTITY);

        // Calculate the number of mixes
        int maxMixWt = 60; // in CWT
        int mixNbr = (int)Math.Ceiling(batchWt / maxMixWt);
        decimal rcmdMixWt = batchWt / (mixNbr < 1 ? 1 : mixNbr);

        
        // Popup displaying recommended action and allow for change
        if (MixSizeDialog.AskExt((graph, view) =>
        {
            MixSizeDialog.Cache.ClearQueryCache();
            MixSizeDialog.View.Clear();
            MixSizeDialog.ClearDialog();
            MixSizeDialog.Current = new MXMixSize() { BatchSize = batchWt * 100, MixSize = rcmdMixWt * 100, MixNbr = mixNbr };
        }, true) != WebDialogResult.OK) return;
        
        mixNbr = (MixSizeDialog.Current.MixNbr ?? 0);
        mixNbr = mixNbr < 1 ? 1 : mixNbr;

        // Calculate the size of each mix
        decimal mixWt = soLine.Qty.Value / mixNbr;
        
        // Create mixes
        for (int i = 0; i < mixNbr; i++)
        {
            MXMix mix = Mixes.Insert(new MXMix());
            Mixes.SetValueExt<MXMix.qty>(mix, mixWt);
            Mixes.SetValueExt<MXMix.uom>(mix, soLine.UOM);
            Mixes.SetValueExt<MXMix.status>(mix, "QUD");
            Mixes.Update(mix);
        }

        Batches.SetValueExt<MXBatch.status>(selectedBatch, 1);
        Batches.Update(selectedBatch);
        Actions.PressSave();
    }

As you can see, my variables are initialized in the block which means they cannot preserve the previous rows values. I added the three lines in the dialog call to clear the data based upon another SO post, but it does not seem to make any difference.

Here's my ASPX:

What am I missing?

Update:

The code that works correctly for me is this:

        MixSizeDialog.View.Clear();
        if (MixSizeDialog.AskExt((graph, view) =>
        {
            MixSizeDialog.Cache.Clear();
            MixSizeDialog.Current = new MXMixSize() { BatchSize = batchWt * 100, MixSize = rcmdMixWt * 100, MixNbr = mixNbr };
        }, true) != WebDialogResult.OK) return;

Additionally, AutoRepaint and AutoReload (and possibly LoadOnDemand) must be true in ASPX.


回答1:


There are a couple of things you can do/check in order to resolve this:

  1. When calling the smart panel view with AskExt ensure that you specify the reload to true. Ex: SmartPanelView.AskExt(true).
  2. Ensure that the AutoReload, LoadonDemand and AutoRepaint properties on the smart panel definition are set to true.

You can also try and clear the cache from the smart panel view before calling the AskExt method, but if you specify true for the reload there shouldn't be any need for this.



来源:https://stackoverflow.com/questions/64787680/why-wont-my-pxsmartpanel-display-the-correct-data-after-the-first-execution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!