Skip to main content
Answer

How to retrieve the selected detail line information from a grid to use in an action in Acumatica?

  • November 13, 2024
  • 4 replies
  • 136 views

Forum|alt.badge.img

I want to retrieve the values of selected detail lines to invoke an action in Acumatica. Some values from the selected detail lines should be passed as parameters to open a custom screen in a popup. How can I retrieve the selected detail line information from a grid to use in an action in Acumatica?

Any detailed instructions, tips, or code snippets would be greatly appreciated. Thank you!

Best answer by darylbowman

As ​@noorula77 hinted at, if by ‘selected’ you mean the currently highlighted grid row, the Current property of the grid-bound data view will be that row if SyncPosition = true in ASPX:

var selectedRow = *viewName*.Current;

If by ‘selected’ you mean a checkbox checked, then this would be the way:

// Retrieve the selected detail lines
var selectedLines = YourViewName.Select().RowCast<YourDetailDAC>().Where(row => row.Selected == true);

 

4 replies

Forum|alt.badge.img+8
  • Captain II
  • November 13, 2024

Hi @RKarunarathne51 

 

I think you should be able to use YourView.Cache.YourSelectField

A Foreach should do the job for you.

 

The declaration of an action is described in the T190, T230, & T270 training courses.

 

Hope this helps,

Aleks


DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi @RKarunarathne51,

You can use below code snippet to start with your requirement.

public PXAction<YourHeaderDAC> CustomAction;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Open Custom Screen")]
protected void customAction()
{
// Retrieve the selected detail lines
var selectedLines = YourViewName.Select().RowCast<YourDetailDAC>().Where(row => row.Selected == true);

foreach (var line in selectedLines)
{
// Access fields from each selected line
var value1 = line.Field1;
var value2 = line.Field2;
}

Hope it helps!


Forum|alt.badge.img+1
  • Jr Varsity III
  • November 15, 2024

 For example you're working with SO Lines in Acumatica and want to show a popup dialog for description editing you can use below approach.

public PXSelect<SOLine,
      Where<SOLine.orderType, Equal<Current<SOOrder.orderType>>,
          And<SOLine.orderNbr, Equal<Current<SOOrder.orderNbr>>,
          And<Where<SOLine.lineNbr, Equal<Current<SOLine.lineNbr>>>>>>> TSTransaction;

        // Custom action for displaying and updating description
        public PXAction<SOOrder> DisplayDescription;
        [PXUIField(DisplayName = "EXT DESC", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXButton(CommitChanges = true)]
        protected virtual IEnumerable displayDescription(PXAdapter adapter)
        {
            // Logic for displaying and updating the description
            if (TSTransaction.AskExt() == WebDialogResult.OK)
            {
                SOLine sOLine = Base.Transactions.Current;
                if (sOLine == null)
                    return adapter.Get();
                Base.Transactions.Update(sOLine);
                Base.Save.Press();

            }

            return adapter.Get();

        }


darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • November 15, 2024

As ​@noorula77 hinted at, if by ‘selected’ you mean the currently highlighted grid row, the Current property of the grid-bound data view will be that row if SyncPosition = true in ASPX:

var selectedRow = *viewName*.Current;

If by ‘selected’ you mean a checkbox checked, then this would be the way:

// Retrieve the selected detail lines
var selectedLines = YourViewName.Select().RowCast<YourDetailDAC>().Where(row => row.Selected == true);