Solved

Conditionally Enable and Loop through SOLines based on Document checkbox

  • 22 April 2023
  • 9 replies
  • 142 views

Userlevel 1
Badge

Im trying to loop through each line of my grid from a checkbox (Auto Assemble Kits) in the main document header to enable/disable all rows of my grid with custom int field usrAutoBuildReq (also check if line IsAKit). Again spent half a day on this and strange behaviours at best?...

 

 

 

    protected void SOOrder_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{

var row = (SOOrder)e.Row;


if (row != null)
{


foreach (SOLine line in Base.Transactions.Select())
{
SOLineExt soLineExt = line.GetExtension<SOLineExt>();
//if IsKit then Enable custom field usrAutoBuildReq

}

}

}

 

icon

Best answer by Dantheman88988 22 April 2023, 13:09

View original

9 replies

Userlevel 7
Badge +8
        protected virtual void _(Events.RowSelected<SOLine> e, PXRowSelected baseHandler)
{
if (e.Row == null) return;

// Call Base Handler
baseHandler?.Invoke(e.Cache, e.Args);

SOOrderExt docExt = Base.Document.Current.GetExtension<SOOrderExt>();
SOLineExt rowExt = e.Row.GetExtension<SOLineExt>();

PXUIFieldAttribute.SetEnabled<SOLineExt.usrAutoBuildReq>(Base.Transactions.Cache, e.Row, docExt.UsrAutoAssembleKits == true && e.Row.IsKit == true);
}

Use the above code. You need RowSelected for SOLine

Userlevel 1
Badge

This code below works quite well. Im using Row Updated in SOOrder so that I can access the DAC extension for the UsrAutoAssembleKits which is in the Document. However the below code is not saving UsrAutoBuildReq to the database? And commit changes are true?

 

protected void SOOrder_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{

var row = (SOOrder)e.Row;
SOOrderExt soOrderExt = row.GetExtension<SOOrderExt>();

if (row != null)
{


foreach (SOLine line in Base.Transactions.Select())
{
SOLineExt soLineExt = line.GetExtension<SOLineExt>();


if(soOrderExt.UsrAutoAssembleKits == true && line.IsKit == true )
{

soLineExt.UsrAutoBuildReq = Convert.ToDecimal(line.OrderQty ?? 0m);
//soLineExt.UsrAutoBuildReq = 10;
}
else
{

soLineExt.UsrAutoBuildReq = null;
}


}


}

}

 

Userlevel 7
Badge +8

The code I provided for sure will enable/disable the lines as you have described. If you have other issues please post a separate thread.

Please note you will need to implement UI controls using RowSelected. If you use RowUpdated the disable/enable logic will only work if a change is made to the header record (in your case). If a user opens a document and doesn’t make a change to the header then the logic won't be triggered and the field you want to disable will NOT be disabled.

I also suggest reading/watching T Series courses to have a better understanding of the events and which should be used when and how.

Thank you.

Userlevel 1
Badge

Hi

 

Yes you were correct. Still dont really know why putting the code under RowUpdated it was not saving the data to the database?

 

Now i have a new issue. Ive successully updated and saved the order with the new value of UsrAutoBuildReq however now Im getting an error message when i try to open the record again? Ive set the DAC field to PXDBDecimal?

 

 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.UsrAutoBuildReq = Convert.ToDecimal(line.OrderQty ?? 0m);
//soLineExt.UsrAutoBuildReq = 10;
}
else
{

soLineExt.UsrAutoBuildReq = null;
}



}



}

 

Userlevel 1
Badge

sorry and screenshot of error

 

 

Userlevel 7
Badge +8

You will need different Events for Different purposes. RowSelected will need to be used for UI handling. But, you shouldn’t be modifying data in RowSelected. Also, I am not sure why you loop on SOLine when SOLine itself is already selected as e.Row. Please separate your issues into separate topics for better response.

Userlevel 1
Badge

Im looping through all lines on the SOLine grid to either set a value for UsrAutoBuildReq depending on the checkbox on the main Document and also the IsKit on the row? Im still getting this cast is not valid?

Userlevel 1
Badge

This was the correct solution anyway for this interested..

 

protected void SOOrder_UsrAutoAssembleKits_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{

if (e.Row == null) return;
InvokeBaseHandler?.Invoke(cache, e);
//var row = (SOLine)e.Row;

SOOrderExt soOrderExt = Base.Document.Current.GetExtension<SOOrderExt>();
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();
}

 

Userlevel 7
Badge

Thank you for sharing your solution with the community @Dantheman88988 !

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved