acumaticaacuminator

Create missing data on RowSelected


We have a graph extension that manages the tab we added to a screen. The tab displays data from our own DAC. We do not use a DAC extension, not going to go into the reasons right now.

When a user opens the main screen I want to create a record of our data if it does not exist, with some defaulting business logic.

I added a RowSelected event handler on the main DAC and it fires as I expect it to. When I add the code to create our missing record in the event handler Acuminator gives me error "PX1044 Changes to PXCache cannot be performed in event handlers."

I understand the error that Acuminator is raising, but I'm not sure where else to create our record. I cannot remember a section of the university specifically addressing this scenario.

Can anyone tell me how I would handle this scenario? And if possible, point me at the learning material that covers this scenario for broader information.


Solution

  • I got a reply from Acumatica support, you can do this in a view select delegate.

    Here's some example code, I haven't tested it though:

    public class InventoryItemMaintExtension : PXGraphExtension<InventoryItemMaint>
    {
        public SelectFrom<MyCustomTable>.
                  Where<MyCustomTable.inventoryID.IsEqual<
                  InventoryItem.inventoryID.FromCurrent>>.
                  View AdditionalItemData;
        public static bool IsActive() { return true; }
    
        public IEnumerable additionalItemData()
        {
            var data = AdditionalItemData.SelectSingle();
            if (data is null)
            {
                data = new MyCustomTable();
                AdditionalItemData.Insert(data);
            }
    
            return AdditionalItemData.Select();
        }
    }
    
    [PXCacheName("Additional Item Data")]
    [Serializable]
    public class MyCustomTable : IBqlTable
    {
        #region CashAccountID
        [Inventory]
        [PXDefault]
        public virtual int? InventoryID { get; set; }
        public abstract class inventoryID : PX.Data.BQL.BqlInt.Field<inventoryID> { }
    
        #endregion
    
        #region Required
        [PXDBBool()]
        [PXDefault(false)]
        [PXUIField(DisplayName = "Required")]
        public virtual bool? Required { get; set; }
        public abstract class required : PX.Data.BQL.BqlBool.Field<required> { }
        #endregion
    }