Skip to main content
Solved

Acumatica Field Updated Event in Production Order Maintanence Screen (AM201500) to Trigger Checkbox in Screen Based on Checkbox in Stock Item Screen

  • October 22, 2024
  • 3 replies
  • 52 views

Forum|alt.badge.img+2

Hi I have a custom checkbox created in the Stock Items screen under the manufacturing screen, when this is checked I need the "Allow Preassigning Lot/Serial Numbers" to be automatically checked as well in the Production Order Maintenance screen. My code works but when the event handler is triggered it clears out the other header fields such as the Inventory ID. How can I fix this?

Custom Checkbox Field
Event Handler to be Applied to this Checkbox
using PX.Objects.Common.Scopes;
using PX.Objects.PM;
using IQtyAllocated = PX.Objects.IN.Overrides.INDocumentRelease.IQtyAllocated;
using LocationStatus = PX.Objects.IN.Overrides.INDocumentRelease.LocationStatus;
using LotSerialStatus = PX.Objects.IN.Overrides.INDocumentRelease.LotSerialStatus;
using SiteLotSerial = PX.Objects.IN.Overrides.INDocumentRelease.SiteLotSerial;
using SiteStatus = PX.Objects.IN.Overrides.INDocumentRelease.SiteStatus;
using System;
using PX.Data;
using PX.Objects.IN;
using PX.Objects.CS;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Objects.AM.GraphExtensions;
using PX.Common;
using PX.Objects.Common;
using PX.Objects.SO;
using PX.Objects.AM.Attributes;
using System.Linq;
using PX.Objects.AM.CacheExtensions;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.GL;
using PX.Objects;
using PX.Objects.AM;
using INInventoryItemExt = PX.Objects.IN.InventoryItemExt;

namespace PX.Objects.AM
{
  public class ProdMaint_Extension : PXGraphExtension<ProdMaint.ItemLineSplittingExtension,PX.Objects.AM.ProdMaint>
  {
   protected virtual void AMProdItem_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (AMProdItem)e.Row;
            if (row?.InventoryID == null) return;

            var item = InventoryItem.PK.Find(Base, row.InventoryID);
            if (item == null) return;

            var itemExt = PXCache<InventoryItem>.GetExtension<INInventoryItemExt>(item);

            cache.SetValueExt<AMProdItem.preassignLotSerial>(row, itemExt.UsrAutoGenerateNumberChecker == true);
        }
      }
}

 

Best answer by Django

protected virtual void AMProdItem_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated baseHandler)
        {

            baseHandler?.Invoke(cache, e);

            var row = (AMProdItem)e.Row;
            if (row?.InventoryID == null) return;

            var item = InventoryItem.PK.Find(Base, row.InventoryID);
            if (item == null) return;

            var itemExt = PXCache<InventoryItem>.GetExtension<INInventoryItemExt>(item);

            cache.SetValueExt<AMProdItem.preassignLotSerial>(row, itemExt.UsrAutoGenerateNumberChecker == true);
        }

Like the above. You add one more parameter to the call and then you can call baseHander?.Invoke(cache, e) when you want to the other code. So if you want to run it before your code, use it early on. If you want your code to run first, then place that call later in your procedure.

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

3 replies

Forum|alt.badge.img+6
  • Captain II
  • 550 replies
  • October 22, 2024

The only thing that jumps out at me is that you’re not calling the existing AMProdItem_InventoryID_FieldUpdated from ProdMaint.


Forum|alt.badge.img+2
  • Author
  • Pro I
  • 103 replies
  • October 22, 2024

@Django thanks for the suggestion, so I would need to call the base method like this?

Base.AMProdItem_InventoryID_FieldUpdated(cache, e);

 


Forum|alt.badge.img+6
  • Captain II
  • 550 replies
  • Answer
  • October 22, 2024
protected virtual void AMProdItem_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated baseHandler)
        {

            baseHandler?.Invoke(cache, e);

            var row = (AMProdItem)e.Row;
            if (row?.InventoryID == null) return;

            var item = InventoryItem.PK.Find(Base, row.InventoryID);
            if (item == null) return;

            var itemExt = PXCache<InventoryItem>.GetExtension<INInventoryItemExt>(item);

            cache.SetValueExt<AMProdItem.preassignLotSerial>(row, itemExt.UsrAutoGenerateNumberChecker == true);
        }

Like the above. You add one more parameter to the call and then you can call baseHander?.Invoke(cache, e) when you want to the other code. So if you want to run it before your code, use it early on. If you want your code to run first, then place that call later in your procedure.


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