Question

How can I change header value of a field based on currently selected row in the grid

  • 4 April 2024
  • 7 replies
  • 130 views

Userlevel 4
Badge +1

Hi all,

 

I want to know how to change header value of a field based on currently selected row in the grid of a form. 

As an Example, if you select the 2nd line of the grid as below. It should change the header field value immediately.

 

This kind of functionality already there in Acumatica. But I was unable to find logic behind there.

As you can see in Production Details Screen, Materials Tab Grid is changing based on user’s selection of above grid lines.

Do you have any idea about this? 

 

Thanks


7 replies

Userlevel 3
Badge

Hi @charithalakshan49 ,

                                          You Can use the Row Updated Event Handler, to achive your requirement

Userlevel 3
Badge

This code worked for me 

protected void AMProdItem_UsrWorkCenterID_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
var row = (AMProdItem)e.Row;
if (row == null) return;

// Retrieve WcID from a matching AMProdOper record
AMProdOper relatedOper = PXSelect<AMProdOper,
Where<AMProdOper.orderType, Equal<Required<AMProdOper.orderType>>,
And<AMProdOper.prodOrdID, Equal<Required<AMProdOper.prodOrdID>>>>
>.Select(Base, row.OrderType, row.ProdOrdID);

if (relatedOper != null)
{
// Display WcID in UsrWorkCenterID field
e.ReturnValue = relatedOper.WcID;

// Optionally, disable editing for display-only field
if (e.Row != null && e.IsAltered)
{
e.ReturnState = PXFieldState.CreateInstance(e.ReturnValue, typeof(string), false, false, null, null, null, null, nameof(AMProdItemExt.usrWorkCenterID), null, null, null, PXErrorLevel.Undefined, false, true, null, PXUIVisibility.Visible, null, null, null);
}
}
}

 

Userlevel 3
Badge

 

 protected void AMProdOper_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var oper = (AMProdOper)e.Row;
if (oper != null)
{
var currentProdItem = Base.ProdItemRecords.Current;
// updating UsrDisplayWcID until after the current event.
sender.Graph.RowSelected.AddHandler<AMProdItem>((cache, args) => DeferUpdateUsrDisplayWcID(cache, oper.WcID));
}
}

// Update UsrDisplayWcID after the RowSelected event completes.
private void DeferUpdateUsrDisplayWcID(PXCache cache, string wcID)
{
var currentProdItem = Base.ProdItemRecords.Current;
if (currentProdItem != null)
{
var prodItemExt = cache.GetExtension<AMProdItemExt>(currentProdItem);
if (prodItemExt.UsrDisplayWcID != wcID)
{
try
{
// Set and update the UsrDisplayWcID field.
cache.SetValueExt<AMProdItemExt.usrDisplayWcID>(currentProdItem, wcID);
cache.Update(currentProdItem);
// Save changes to persist in the database.
Base.Actions.PressSave();
}
catch (Exception ex)
{
// Log error and rethrow.
PXTrace.WriteError(ex);
}
}
}
}
}
}

There were some issues with the code above. This code works fine. If any changes, I'll update them here

Userlevel 3
Badge

Hi


This code functions well, but there's a minor issue: the UsrWorkCenterID field doesn't update automatically. I need to clear the current record to obtain the new value. I'm not sure if this requires changes to the layout properties. If anyone knows how to resolve this, please share the solution.

Thank you.

protected void AMProdItem_UsrWorkCenterID_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
// Getting the production item data.
var prodItemRow = (AMProdItem)e.Row;
if (prodItemRow == null) return; // If there's no data, return.

// Trying to find the current operation info.
var currentOperRow = Base.Caches<AMProdOper>().Current as AMProdOper;

// If the current operation matches the item's details, use its Work Center ID.
if (currentOperRow != null && currentOperRow.ProdOrdID == prodItemRow.ProdOrdID)
{
e.ReturnValue = currentOperRow.WcID;
}
else
{
// If not, look for related operations to find a Work Center ID.
var relatedOper = PXSelect<AMProdOper,
Where<AMProdOper.orderType, Equal<Required<AMProdOper.orderType>>,
And<AMProdOper.prodOrdID, Equal<Required<AMProdOper.prodOrdID>>>>
>.SelectWindowed(Base, 0, 1, prodItemRow.OrderType, prodItemRow.ProdOrdID);

// If a related operation is found, set the return value to its Work Center ID.
if (relatedOper != null && relatedOper.Count > 0)
{
e.ReturnValue = ((AMProdOper)relatedOper).WcID;
}
}
}

 

Userlevel 5
Badge +3

Take a note of aspx page changes with RepaintControlIDs as show on the screenshot:

 

Userlevel 5
Badge +3

Please check this link for additional information:

https://help.acumatica.com/(W(1))/Wiki/ShowWiki.aspx?pageid=a23d3b80-e763-46da-9beb-c1447ceae4b3

and also developers guide: https://www.acumatica.com/media/2020/02/AcumaticaFramework_DevelopmentGuide.pdf

 

Userlevel 3
Badge

Please check below thread for more updates

 

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