How to create a hyperlink user field

I have a user field which displays the ARRegister.RefNbr. This user field is contained in the APTran grid. The user actually creates an AR invoice with a custom action, and the new AR document ref nbr is saved to the APTran grid. I wish to craft the user field as a hyperlink (similar to the inventory receipt reference number, in the SO shipment order tab). Should I use a PXSelector control? What are the proper attributes? The goal is to open the AR invoice screen, when the user click on the user field.


Solution 1:

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.

Solution 2:

If you have a selector linked to a standard Acumatica table such as adding a custom field that contains a selector against InventoryItem or ARInvoice you can set the AllowEdit=True on your field in the page containing your custom field. This will automatically add the hyperlink. If your field does not contain the selector it will not work unless maybe setup for segments.

We have custom tables we added to our project where we wanted hyperlinks. As long as you add the PXPrimaryGraph attribute on your DAC you should be able to do the same for a complete custom page/dac.

We started off using the LinkCommand but the AllowEdit approach keeps the code simple without the need for custom logic to support the link. More complex logic than going to the fields primary graph would require a linkcommand.