How to create a hyperlink user field

There is a generic approach that allows you to add links to the grid cells and isn’t based on selectors or anything else. To implement it you have to do the following steps:

1.Define an action in your graph that handles redirects. Something like this:

public PXAction<YourMainDAC> ViewInvoice;

[PXButton]
protected virtual void viewInvoice()
{
    ARTran row = Transactions.Current;
    string docType = //get Doc Type from the tran record
    string refNbr = //get Ref Nbr from the tran record
    ARInvoice invoice = PXSelect<ARInvoice, 
        Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>,
          And<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>>
            .Select(this, row.YourDocTypeField, row.YourRefNbrField);

    // Create the instance of the destination graph
    ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
    graph.Document.Current = invoice;

    // If the invoice is found, throw an exception to open
    // a new window (tab) in the browser
    if (graph.Document.Current != null)
    {
        throw new PXRedirectRequiredException(graph, true, "AR Invoice");
    }
}

2.In the .aspx page definition add a callback command that corresponds to the new action (substitute grid with the ID of the ARTrans grid on your page):

<px:PXDataSource ID="ds" ... >
    <CallbackCommands>
        <px:PXDSCallbackCommand Name="ViewInvoice"
            Visible="False"
            DependOnGrid="grid">
        </px:PXDSCallbackCommand>
    </CallbackCommands>
</px:PXDataSource>

3.In the grid column where you want to add a link specify link command to point to the above PXDSCallbackCommand:

<px:PXGridColumn DataField="InvoiceNbrOrSomething"
                 LinkCommand="ViewInvoice">
</px:PXGridColumn>

This is a bit lengthy way of defining a link but, first, it does not impose any constraints on the field where you add a link and it also gives you full control over which graph to open and what to show there.

Note: you may also need to set SyncPosition="true" on the grid control in the aspx.

The example is adapted from the Example 3.4 in the Acumatica T200 training guide. You may want to check it out for some thorough explanations and more info.

Leave a Comment