0
votes

with code from Load value from popup to InventoryID field question am able to set the InventoyID from popup to the InventoryID field but the default behavior of Acumatica is missing, like after InventoryID is set from poup, am selecting Item Class then a pop up is firing and asking for confirmation, generally this happen only when we update Item Class for already created Item.

    [PXButton]
    [PXUIField(DisplayName = "Generate")]
    public IEnumerable GenerateInv(PXAdapter adapter)
    {
        string inventoryCD = "ACUMATICA";

        InventoryItem item = PXCache<InventoryItem>.CreateCopy(Base.Item.Current);

        OrderedDictionary keys = new OrderedDictionary(StringComparer.OrdinalIgnoreCase) 
            {
                {
                    typeof(InventoryItem.inventoryCD).Name, 
                    adapter.View.Cache.GetValue(adapter.View.Cache.Current, 
                    typeof(InventoryItem.inventoryCD).Name)
                }
            };

        OrderedDictionary vals = new OrderedDictionary(StringComparer.OrdinalIgnoreCase) 
            { 
                { 
                    typeof(InventoryItem.inventoryCD).Name, inventoryCD 
                } 
            };

        adapter.View.Cache.Update(keys, vals);

        if (adapter.Searches != null && adapter.Searches.Length > 0)
        {
            adapter.Searches[0] = inventoryCD;
        }
        return adapter.Get();
    }
1

1 Answers

0
votes

You can try to skip the message window by overriding the Field Verifying on the stock item page for InventoryItem.ItemClassID. You should use some condition to indicate you are running your customer process so the standard message will appear for normal use on the stock items page.

public virtual void InventoryItem_ItemClassID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying del)
{
    try
    {
        del?.Invoke(cache, e);
    }
    catch (PXDialogRequiredException)
    {
        var someSkipMessageWindowCondition = true;
        if (someSkipMessageWindowCondition)
        {
            return;
        }
        throw;
    }
}

Because of the use of the private property doResetDefaultsOnItemClassChange in the Base graph, the process will function as if the message box was answered YES to default the field values from the new item class. If you do not want the values to change using the new class you will need to cancel the field defaultings for the fields found in InventoryItem_ItemClassID_FieldUpdated in the Base graph. This will point out which fields are being updated when doResetDefaultsOnItemClassChange == true.

A better answer to your question would be automatically answering NO which I am unsure how to do. Would be nice to know how do perform that function if someone else knows how to make that call.