Skip to main content
Solved

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


Forum|alt.badge.img+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

Best answer by Atiq

Hi @charithalakshan49 ,

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

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

7 replies

Atiq
Jr Varsity III
Forum|alt.badge.img
  • Jr Varsity III
  • 38 replies
  • Answer
  • April 5, 2024

Hi @charithalakshan49 ,

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


Forum|alt.badge.img

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

 


Forum|alt.badge.img

 

 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


Forum|alt.badge.img

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

 


Yuriy Zaletskyy
Jr Varsity I
Forum|alt.badge.img+3

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

 


Yuriy Zaletskyy
Jr Varsity I
Forum|alt.badge.img+3

Forum|alt.badge.img

Please check below thread for more updates

 


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