Retrieving data fields from subgrid

This is probably a request that has been required many times, but recently, one of our customers had a request to open an OnBase document based on some data that was available in a subgrid. Since OnBase has a web to query the database using a query string in their web application, this seemed to be an easy enough solution.


The first step was to create a button on the ribbon that will call a JavaScript function that will in turn execute the OnBase function call. To do this we created a button on the Command Bar of the entity using Ribbon Workbench. You can view our previous published post on how to create a button using Ribbon Workbench if you need further assistance with this process.

In this case we created a button called OnBase, which calls the showOnBase function and passes the CommandProperties. The reason that it is passing the CommandProperties, is that the button has various options for that same form. The image below shows the button that was created using Ribbon Workbench. This is a flyout button, thus has various different options.

Command Bar Flyout Button

Next we need to enter the JavaScript for the flyout button. In our case we used a single function for the flyout and passed the CommandProperties, in order to get the name of the button that was clicked. The following Script shows how to find out which button was clicked, and based on that we will be calling our process.

function showOnBase(CommandProperties)
    var controlId = CommandProperties.SourceControlId;
    var menuItemId = controlId.split('|')[3];
    var recordType = menuItemId.split('.')[2];
    switch (recordType)
        case "OnBaseContract":
        case "OnBasePurchaseOrder":
        case "OnBaseInvoice":

In our particular case, we are interested in getting the value for a subgrid, which means that the user would have to select the record from a subgrid and the click on the appropriate button. The image below shows our Purchase Order subgrid. When the user selects the PO subgrid row, and the clicks on the Command Bar Purchase Order command, we will open up the Purchase Order using OnBase. The image below displays the PO subgrid.

Selected Record on Subgrid

We can not get the purchase order number from the selected record and Open OnBase.

function showOnBasePurchaseOrder()
    var selectedRows = Xrm.Page.getControl("PurchaseOrders").getGrid().getSelectedRows();
    var selectedRow = selectedRows.getAll()[0];

    var attributes = selectedRow.getData().getEntity().getAttributes().getAll();
    // scag_ponumber
    attributes.forEach(function (attribute) {
        var attributeName = attribute.getKey();
        if (attributeName == "new_ponumber")
            var poNumber = attribute.getValue();
            var url = "http://ecmweb/AppNet/docpop/docpop.aspx?KT123_0_0_0=" + poNumber + "&clienttype=activex&cqid=111";

function openOnBase(url)

 You can use different methods to open your OnBase form if you don't want to use the, but this was a good option for the purpose that we needed.