This blog post will guide you through the process of creating a Command Ribbon Button in a Model-Driven App. This button will open a SharePoint library in a new tab, pre-filtered to show only documents related to the current record in Dynamics 365. This is achieved by dynamically generating a URL based on the current record’s GUID.

Understanding SharePoint’s URL Filtering

Before proceeding, it’s crucial to understand how SharePoint filters records through URL parameters. Navigate to the SharePoint library and experiment with different filters. Observe the URL to see how it changes with each filter. Typically, you’ll find parameters like filterValue= followed by your filtering criteria.

Steps to Create the Command Bar Button

Step 1: Open Model-Driven App Editor

Open the Model-Driven App Editor and navigate to the command bar editor for the primary record’s main form.

Edit Command Bar

Step 2: Create a New Button

Create a new button and label it “SharePoint”.

Step 3: Set up Power Fx Run Formula

In this step, we’ll use Power Fx to set up the Run Formula action. You’ll be inserting the formula into the OnSelect property of the button.

Example Power Fx Code

Here’s an example based on a SharePoint Library located at https://<yourorghere> You will need to find and insert your own SharePoint URL.

Power Fx Code


Code Explanation

  • Launch(): This function opens a new browser window or tab.
  • Inside Launch(), we’re concatenating the base URL of the SharePoint Library with filtering parameters:
    • FilterField1=Patient%5Fx0020%5FGUID: Specifies that we want to filter based on a SharePoint library column named “Patient GUID”.
    • FilterValue1=: This is the value that we’ll be filtering on.
  • & Self.Selected.Item.Contact: This part dynamically appends the GUID of the selected contact record from the Model-Driven App to complete the filtering criterion.

Once the button is clicked, it triggers this Power Fx code to launch a new tab that opens the SharePoint Library, pre-filtered based on the current record’s GUID.

Step 4: Save and Publish

After you’ve set up the Power Fx code, save and publish your changes.


Once published, the button will appear in the Model-Driven App. Users can click it to open a new tab showing only documents related to the current record’s GUID. This makes it easier for users to find relevant documents quickly.

SharePoint Button Model-Driven App

For more, check out the other posts in this series:

Meta Data Tagging

Creating & Adding Documents

Copying file from CRM field to CRM Library

SharePoint and Dynamics 365 Integration

Viewing PDFs in Canvas Apps