I would like to enable / disable the command button below ASSEMBLE KITS REQUEST based on the checkbox Auto Assemble Kits (UsrAutoAssembleKits). The command button is linked to an action and working correctly thanks to
![](https://uploads-us-west-2.insided.com/acumatica-en/attachment/d45fe639-a30f-4e88-9d7b-fb54e5f58221.png)
namespace PX.Objects.SO
{
public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
public PXAction<PX.Objects.SO.SOOrder> UsrKitsAssembleReq;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Assemble Kits Request")]
public virtual IEnumerable usrKitsAssembleReq(PXAdapter adapter)
{
if (Base.Document.Current != null)
{
SOOrderExt soOrderExt = Base.Document.Current?.GetExtension<SOOrderExt>();
SOOrder soOrder = (SOOrder)Base.Caches[typeof(SOOrder)].Current;
if(soOrder.OrderNbr.Contains("NEW") == false){
if(soOrderExt.UsrKitsAssembleReq == null || soOrderExt.UsrKitsAssembleReq == false){
soOrderExt.UsrKitsAssembleReq = true;
Base.Document.Cache.Update(Base.Document.Current);
Base.Save.Press();
Base.Document.View.Ask("Autobuild Request Sent. Please refresh in several minutes.", MessageButtons.OK);
}
}
}
return adapter.Get();
}
public PXSelect<INRegister, Where<INRegister.tranDesc, Contains<Current<SOOrder.orderNbr>>, And<INRegisterExt.usrAutoBuild, Equal<True>>>> KitAssView;
#region Event Handlers
protected void SOLine_OrderQty_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
if (e.Row == null) return;
if (Base.Document.Current == null) return;
var row = (SOLine)e.Row;
SOLineExt soLineExt = row.GetExtension<SOLineExt>();
if((decimal?)soLineExt.UsrAutoBuildReq2 > (decimal?)row.OrderQty)
{
soLineExt.UsrAutoBuildReq2 = (row.OrderQty ?? 0m);
}
}
protected void SOOrder_UsrAutoAssembleKits_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
if (e.Row == null) return;
//var row = (SOLine)e.Row;
SOOrderExt1 soOrderExt = Base.Document.Current.GetExtension<SOOrderExt1>();
Base.Document.Cache.AllowUpdate = true;
Base.Transactions.Cache.AllowUpdate = true;
foreach (SOLine line in Base.Transactions.Select())
{
SOLineExt soLineExt = line.GetExtension<SOLineExt>();
if(soOrderExt.UsrAutoAssembleKits == true && line.IsKit == true )
{
soLineExt.UsrAutoBuildReq2 = Convert.ToDecimal(line.OrderQty ?? 0m);
PXUIFieldAttribute.SetEnabled<SOLineExt.usrAutoBuildReq2>(Base.Transactions.Cache, line, true);
}
else
{
soLineExt.UsrAutoBuildReq2 = null;
PXUIFieldAttribute.SetEnabled<SOLineExt.usrAutoBuildReq2>(Base.Transactions.Cache, line, false);
}
Base.Transactions.Update(line);
}
Base.Transactions.View.RequestRefresh();
}
protected void SOLine_UsrAutoBuildReq2_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
{
if (e.Row == null) return;
if (Base.Document.Current == null) return;
var row = (SOLine)e.Row;
SOLineExt soLineExt = row.GetExtension<SOLineExt>();
if((decimal?)e.NewValue > (decimal?)row.OrderQty)
{
e.NewValue = (row.OrderQty ?? 0m);
}
}
protected void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
if (e.Row == null) return;
InvokeBaseHandler?.Invoke(cache, e);
//var row = (SOLine)e.Row;
SOOrderExt1 soOrderExt = Base.Document.Current.GetExtension<SOOrderExt1>();
Base.Document.Cache.AllowUpdate = true;
Base.Transactions.Cache.AllowUpdate = true;
foreach (SOLine line in Base.Transactions.Select())
{
SOLineExt soLineExt = line.GetExtension<SOLineExt>();
if(soOrderExt.UsrAutoAssembleKits == true && line.IsKit == true )
{
//soLineExt.UsrAutoBuildReq2 = Convert.ToDecimal(line.OrderQty ?? 0m);
PXUIFieldAttribute.SetEnabled<SOLineExt.usrAutoBuildReq2>(Base.Transactions.Cache, line, true);
}
else
{
//soLineExt.UsrAutoBuildReq2 = null;
PXUIFieldAttribute.SetEnabled<SOLineExt.usrAutoBuildReq2>(Base.Transactions.Cache, line, false);
}
if((decimal?)soLineExt.UsrKitQtyAvail < (decimal?)soLineExt.UsrAutoBuildReq2)
{
PXUIFieldAttribute.SetWarning<SOLineExt.usrAutoBuildReq2>(Base.Transactions.Cache, line, "Warning, not enough kits available to autobuild. Component quantities may go negative.");
}
else
{
PXUIFieldAttribute.SetWarning<SOLineExt.usrAutoBuildReq2>(Base.Transactions.Cache, line, null);
}
//Base.Transactions.Update(line);
}
Base.Transactions.View.RequestRefresh();
}
protected virtual void _(Events.RowSelected<SOLine> e, PXRowSelected baseHandler)
{
// if (e.Row == null) return;
// baseHandler?.Invoke(e.Cache, e.Args);
// var row = (SOLine)e.Row;
// SOOrderExt soOrderExt = Base.Document.Current.GetExtension<SOOrderExt>();
// foreach (SOLine line in Base.Transactions.Select())
// {
// SOLineExt soLineExt = line.GetExtension<SOLineExt>();
// if(soOrderExt.UsrAutoAssembleKits == true && line.IsKit == true )
// {
// soLineExt.UsrAutoBuildReq2 = Convert.ToDecimal(line.OrderQty ?? 0m);
//soLineExt.UsrAutoBuildReq = 10;
// }
// else
// {
// soLineExt.UsrAutoBuildReq2 = null;
// }
// }
}
protected void SOLine_SiteID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
var row = (SOLine)e.Row;
if (row != null && row.SiteID !=null && row.InventoryID != null)
{
SOLineExt soLineExt = row.GetExtension<SOLineExt>();
//Get the KitAssy record
AutoKitAssembly.KitAssy kitAssy = PXSelectReadonly<AutoKitAssembly.KitAssy,
Where<AutoKitAssembly.KitAssy.builtItemID, Equal<Required<AutoKitAssembly.KitAssy.builtItemID>>,
And<AutoKitAssembly.KitAssy.siteId, Equal<Required<AutoKitAssembly.KitAssy.siteId>>>>>
.Select(Base, row.InventoryID, row.SiteID);
if (kitAssy != null)
{
soLineExt.UsrKitQtyAvail = (kitAssy.QtyAvail ?? 0m);
}
else
{
soLineExt.UsrKitQtyAvail = null;
}
}
}
protected void SOLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
var row = (SOLine)e.Row;
if (row != null && row.SiteID !=null && row.InventoryID != null)
{
SOLineExt soLineExt = row.GetExtension<SOLineExt>();
//Get the KitAssy record
AutoKitAssembly.KitAssy kitAssy = PXSelectReadonly<AutoKitAssembly.KitAssy,
Where<AutoKitAssembly.KitAssy.builtItemID, Equal<Required<AutoKitAssembly.KitAssy.builtItemID>>,
And<AutoKitAssembly.KitAssy.siteId, Equal<Required<AutoKitAssembly.KitAssy.siteId>>>>>
.Select(Base, row.InventoryID, row.SiteID);
if (kitAssy != null)
{
soLineExt.UsrKitQtyAvail = (kitAssy.QtyAvail ?? 0m);
}
else
{
soLineExt.UsrKitQtyAvail = null;
}
}
}
#endregion
}
}