Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a hyperlink user field

Tags:

acumatica

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.

like image 592
Chris H Avatar asked Dec 12 '22 03:12

Chris H


1 Answers

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.

like image 99
Alex Turok Avatar answered Jan 14 '23 04:01

Alex Turok