Skip to main content

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 @Naveen Boga.. I assume its connected with the Field_Updated event. the ID for the command button is CMD3

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
}
}

 

You can enable / disable your button in SOOrder_RowSelected:

UsrKitsAssembleReq.SetEnabled(soOrderExt.UsrAutoAssembleKits == true);

 


Thanks though I'm trying to enable / disable the command button not the checkbox?


Well, I think UsrKitsAssembleReq is your Action linked to your button. You can enable / disable the action and it will take care of your button.


Thanks that seems to work now though when the sales order form opens first on a new record its defaults to Enabled = true? Ive tried setting the property in the form editor to AutoCallback → Enabled = false but it still loads as enabled?


Can you show me how you disable it in RowSelected?


Hi @Dantheman88988  According to your requirement, the Button should be displayed at the GRID Header/ Toolbar button (Just like the Add Items, Line Details, and Item Availability buttons)

To enable/disable the grid button will not work with the enable/disable button code in the RowSelected event.

Please refer to the below link, it helps with your requirements. Let me know if you have any queries.

 

https://blog.zaletskyy.com/post/2015/01/27/post78

 


Reply