Skip to main content
Answer

Grid is not using currently selected row

  • April 24, 2025
  • 3 replies
  • 139 views

DrewNisley
Pro I
Forum|alt.badge.img+3

I have a grid where I have sales orders and service orders in the same field. I want to make this a hyperlink, so I used the callback command and a custom redirect action. That works and redirects properly, but it pulls the data from the first row instead of the one currently selected. I’ve tried the SyncPosition = true and making sure the dac has a key field, but to no avail. Would anyone be able to help me out? Thanks.

    <CallbackCommands>
<px:PXDSCallbackCommand CommitChanges="True" Name="ViewDocument" Visible="False" DependOnGrid="Details" ></px:PXDSCallbackCommand></CallbackCommands>
.
.
.
.
.
<px:PXTabItem Text="Details">
<Template>
<px:PXGrid SyncPosition="True" Height="100%" Width="100%" AutoAdjustColumns="True" runat="server" ID="Details" SkinID="Inquire" AllowPaging="False">
<Levels>
<px:PXGridLevel DataMember="Details">
<Columns>
<px:PXGridColumn DataField="InventoryID" Width="70" ></px:PXGridColumn>
<px:PXGridColumn DataField="DocType" Width="70" ></px:PXGridColumn>
<px:PXGridColumn LinkCommand="ViewDocument" DataField="OrderNbr" Width="70" ></px:PXGridColumn>
.
.
.
public PXAction<InventoryDiscrepenciesFilter> ViewDocument;
[PXButton]
[PXUIField(DisplayName = "ViewDocument", MapEnableRights = PXCacheRights.Select)]
protected virtual void viewDocument()
{
InventoryDiscrepenciesDetails row = Details.Current;

SOOrder salesOrder = PXSelect<SOOrder, Where<SOOrder.orderType, Equal<Required<InventoryDiscrepenciesDetails.orderType>>,
And<SOOrder.orderNbr, Equal<Required<InventoryDiscrepenciesDetails.orderNbr>>>>>.Select(this, row?.OrderType, row?.OrderNbr);
FSServiceOrder srvOrder = PXSelect<FSServiceOrder, Where<FSServiceOrder.srvOrdType, Equal<Required<InventoryDiscrepenciesDetails.orderType>>,
And<FSServiceOrder.refNbr, Equal<Required<InventoryDiscrepenciesDetails.orderNbr>>>>>.Select(this, row?.OrderType, row?.OrderNbr);
if (salesOrder != null)
{
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();

graph.Document.Current = salesOrder;

if (graph.Document.Current != null)
{
throw new PXRedirectRequiredException(graph, true, "Sales Orders")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
}
}
else if (srvOrder != null)
{
ServiceOrderEntry graph = PXGraph.CreateInstance<ServiceOrderEntry>();

graph.ServiceOrderRecords.Current = srvOrder;

if (graph.ServiceOrderRecords != null)
{
throw new PXRedirectRequiredException(graph, true, "Service Orders")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
}
}

return;
}
public PXFilter<InventoryDiscrepenciesFilter> Filter;
public PXFilter<InventoryDiscrepenciesDetails> Details;

 

Best answer by DrewNisley

The issue turned out to be a combination of a few things. I am using a view delegate and at first I wasn’t inserting the records using the insert action, meaning the PXDBIdentity never assigned a value to the key field. So to fix that, I had started using “return Details.Insert(row);” That seemed to allow it to at least redirect, just to the wrong record, so I assumed it was fine. Turns out it was causing issues, so I switched my key field to PXDBInt instead and just assigned it a value in my delegate manually and reverted to “return row” instead and that fixed the issue.

Thank you ​@Saikrishna V though, I would’ve completely forgotten to switch that.

3 replies

Patrick Chen
Varsity II
Forum|alt.badge.img+2
  • Varsity II
  • April 24, 2025

Hi Drew  Your code looks good.  I would check your DAC and make sure that the key field’s definition matches the SQL exactly.  The graph can get confused if the data types are off, you’re missing a key designator, or something is set to nullable or not when it shouldn’t be.


Forum|alt.badge.img+1
  • Semi-Pro III
  • April 24, 2025

Hello ​@DrewNisley 

As far as I know, the problem is because Details view is using PXFilter, which only holds one row and doesn’t track which grid row was clicked. So it always returns the same row, usually the first one.

To fix it, can you try change Details to use PXSelect instead.

 

Hope this helps.


DrewNisley
Pro I
Forum|alt.badge.img+3
  • Author
  • Pro I
  • Answer
  • April 25, 2025

The issue turned out to be a combination of a few things. I am using a view delegate and at first I wasn’t inserting the records using the insert action, meaning the PXDBIdentity never assigned a value to the key field. So to fix that, I had started using “return Details.Insert(row);” That seemed to allow it to at least redirect, just to the wrong record, so I assumed it was fine. Turns out it was causing issues, so I switched my key field to PXDBInt instead and just assigned it a value in my delegate manually and reverted to “return row” instead and that fixed the issue.

Thank you ​@Saikrishna V though, I would’ve completely forgotten to switch that.