Monthly Archives: October 2019

How to Integrate Microsoft Dynamics 365 Online with SharePoint and OneNote

In this post, we cover how to integrate Microsoft Dynamics 365 Online with SharePoint and OneNote. We start off with why you should consider integrating Dynamics 365 with SharePoint and OneNote. Secondly, a full step-by-step guide is provided on how to create a SharePoint Site for Dynamics 365 document management. Thirdly, a detailed guide on how to integrate Microsoft Dynamics 365 Online with SharePoint Online is provided. We conclude with an elaborate guide of how to integrate Microsoft Dynamics 365 Online with OneNote.

Why Consider Integrating Dynamics 365 with SharePoint and OneNote?

  • Cost: It is cheaper to store documents in Microsoft SharePoint than in Microsoft Dynamics 365 online.
  • Enhanced document Management functionality: SharePoint online is a Microsoft platform that specializes in document management and hence has more enhanced features focused on document management e.g. creating sub-sites, information rights management, SharePoint business intelligence, etc.
  • Enhance collaboration: teams can retain the great Dynamics 365 collaboration tools while also utilizing the advance document management features of SharePoint.
  • Enhanced productivity: by allowing users to access documents in multiple places. If someone is working in SharePoint, they do not need to go back to Dynamics 365 to access documents uploaded in Dynamics 365.
  • Seamless user experience: Despite the documents are stored in SharePoint after the integration, to a Dynamics 365 Online user, it feels like the documents still reside in Dynamics 365. The user experience is not compromised by this integration.

How To Create a SharePoint Site for Dynamics 365 Document Management

Step 1: Login in to https://admin.microsoft.com as a global or SharePoint administrator. If you see a notification that you have no permission to access the page, you do not have SharePoint administrator rights or Office 365 global administrator permissions in your organization.

Step 2: In the left pane, under Admin centers, select SharePoint. You might need to select Show all to see the full list of admin centers. This will take take you to the SharePoint home page.

Step 3: On the SharePoint home page, click Create site to start the process of creating a SharePoint site.
SharePoint Home Page

Step 4: You will get pop up window, asking you to choose the type of SharePoint site you would like to create. Choose Team site:
Choosing type of SharePoint site to create

Step 5: Enter details about your team site. Take note of Site Address, we will need it later when integrating Microsoft Dynamics 365 with this SharePoint team site. Afterwards click Next.
3.2. Enter details about the SharePoint Site

Step 6: You can add members and/or additional owners of the site. This is not a required step, you can come and add site owners and additional members later after you have created the site. Click Finish to complete the process of creating your SharePoint site.
Add site members and additional owners

Step 7: After Step 6, your new site will be created and it will look similar to:
New SharePoint team site

Integrating Dynamics 365 Online With SharePoint

For this demonstration, we are using version 9.1.0000.9825 of Dynamics 365 (2019 release wave 2 enabled) online. However, the integration process is the same or very similar in other versions of Dynamics 365/CRM online.

Step 1: In your Dynamics 365/CRM instance, login with the System Administrator and/or System Customizer security role. Then navigate to Settings >> Document Management. On this page, click on Configure Server-Based SharePoint Integration.
D365 Document Management Page

Step 2: You will get the following pop up, asking you where your SharePoint sites are located. In this demonstration, we are working with Dynamics 365 online and SharePoint online, so the Online option is selected. Afterwards, click Next.
Choose location of SharePoint site

Step 3: Enter the URL of the SharePoint Site (see Step 5 of section How To Create a SharePoint Site for Dynamics 365 Document Management above). A check will be conducted on whether the URL you have provided is a valid SharePoint online site and if it exists in the same Office 365 tenant as your Dynamics 365 organization. After enabling server-based SharePoint integration, you cannot go back to the client-side integration, the default setting prior to this integration.  If you would like to proceed, click Next.
Enter SharePoint Site URL

Step 4: After your SharePoint site has been validated by Dynamics 365, click Finish.
Validation of SharePoint site by Dynamics 365

Step 5: In Dynamics 365, go to Settings >> Document Management. You will notice that the Configure Server-Based SharePoint Integration option, mentioned in Step 1, is no longer available. This is because we have correctly configured Dynamics 365 with SharePoint. On this page, now click on Document Management Settings to complete the process of integrating Dynamics 365 with SharePoint.
Document Management Settings

Step 6: After executing the previous step, the window below will pop up, where you can select the Dynamics 365 entities you would like to enable for document management in SharePoint. Afterwards click Next to continue the integration process.
Configure Dynamics 365 entities for document management

Step 7: Select the SharePoint folder structure for the entities selected in the previous step. In the example below, I have selected a folder structure based on entities. Afterwards, click Next.
Choose SharePoint folder structure

Step 8: The following window will pop up. Click OK, if you would like to proceed with the creation of document libraries in the provided SharePoint site.
SharePoint Document Libraries Creation

Step 9: Wait until the document libraries have been created. After the document libraries have been created you will get a window similar to the one below, notifying you that the process has been completed. Click Finish.
Document Library Creation Process Complete

You have successfully enabled Dynamics 365 for document management in SharePoint. For the entities enabled, files uploaded for their records will be stored in SharePoint and you can make utilize the full range of document management capabilities offered by SharePoint. Your documents will be accessible in both Dynamics 365 and SharePoint.

To view the SharePoint sites enabled for document management in your Dynamics 365 organization, go to Settings >> Document Management. Click on SharePoint Sites. You will get a window similar to the one below:
Active SharePoint Sites for Dynamics 365 Organization

To view the Dynamics 365 entities’ folders created in SharePoint, navigate to the SharePoint team site you provided above. In the left navigation panel, click on Site Contents. You will get a window similar to:
Dynamics 365 entities' folders in SharePoint

Integrating Dynamics 365 Online With OneNote

Step 1: In Dynamics 365, go to Settings >> Document Management. On this page, click on OneNote Integration.
OneNote Integration

Step 2: After executing the previous step, the window below will pop up, where you can select Dynamics 365 entities you would like to enable for OneNote Integration. Click Finish to complete the process.
Choose the entities to enable for OneNote Integration

You have successfully integrated Dynamics 365 with OneNote. For records of the enabled entities, notes made in Dynamics 365 will be synced with OneNote in SharePoint Online. Also, you can access these notes on your desktop (i.e. OneNote Desktop) and mobile devices (i.e. OneNote Mobile).

Dynamics 365: How To Get and Set Fields on Forms Using JavaScript

In this post, we will cover how to get and set values for fields on Microsoft Dynamics 365/CRM forms. Dynamics 365 has the following types of fields (or datatypes): Single Line of Text, Option Set, MultiSelect Option Set, Two Options, Image, Whole Number, Floating Point Number, Floating Point Number, Decimal Number, Currency, Multiple Lines of Text, Date and Time, Lookup and Customer.

At the time of writing, there are two ways of accessing fields on Dynamics 365 forms i.e. using the formContext JavaScript API and Xrm.Page JavaScript API. However, Microsoft has the following JavaScript API recommendations:

  • Before Dynamics 365/CRM version 9.0, use the Xrm.Page API:
    Xrm.Page.getAttribute(fieldName);
  • Version 9.0 of Dynamics 365/CRM and after, use the formContext API:
    executionContext.getFormContext().getAttribute(fieldName);

With the release of version 9.0 of Dynamics CRM/365, Microsoft announced that it would deprecate the Xrm.Page JavaScript API. For details on how you can transition from the Xrm.Page API to the formContext API, see my earlier post: Quick Guide: Transitioning away from Microsoft Dynamics 365 Xrm.Page JavaScript API. From Xrm.Page to formContext, how you get and set values has not fundamentally changed. However, how you access fields and other form properties has changed.

Single Line of Text

Here is an example of a Single Line of Text field on a Dynamics 365 form:
Single Line of Text field

Here is the JavaScript for getting and setting the value of a Single Line of Text field (Display Name: “Account Number” | Database Name: “accountnumber”):

//Get and Set a Single Line of Text field value
function SingleLineOfTextFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var accountNumberFieldLogicalName = "accountnumber";
    //Access the field on the form
    var accountNumberField = formContext.getAttribute(accountNumberFieldLogicalName);
    //Declare the other variables as needed
    var accountNumberFieldValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (accountNumberField != null) {
        // Get the value of the field
        accountNumberFieldValue = accountNumberField.getValue();

        // Set the value of the field
        accountNumberField.setValue("BYA-2019-AIR-0099");
    }
}

Multiple Lines of Text

Here is an example of a Multiple Lines of Text field on a Dynamics 365 form:
Multiple Lines of Text field

Here is the JavaScript for getting and setting the value of a Multiple Lines of Text field (Display Name: “Description” | Database Name: “description”):

//Get and Set Multiple Lines of Text field value
function MultipleLineOfTextFieldValue(executionContext) {
    debugger;
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var descriptionFieldLogicalName = "description";
    // Access the description field on the form
    var descriptionField = formContext.getAttribute(descriptionFieldLogicalName);
    //Declare the other variables as needed
    var descriptionFieldValue;
    var exampleText = "\
            To be, or not to be, that is the question:\
            Whether 'tis nobler in the mind to suffer\
            The slings and arrows of outrageous fortune,\
            Or to take Arms against a Sea of troubles,\
            And by opposing end them: to die, to sleep;\
            No more; and by a sleep, to say we end \
            The heart - ache, and the thousand natural shocks \
            That Flesh is heir to ? 'Tis a consummation \
            Devoutly to be wished.To die, to sleep, \
            perchance to Dream; aye, there's the rub, \
            For in that sleep of death, what dreams may come, \
            When we have shuffled off this mortal coil,\
            Must give us pause. "  ;

    //Check that field exist on the form before you try to Get/Set its value
    if (descriptionField != null) {
        // Get the value of the description field
        descriptionFieldValue = descriptionField.getValue();

        // Set the value of the description field
        descriptionField.setValue(exampleText);
    }
}

Whole Number

Here is an example of a Whole Number field on a Dynamics 365 form:
Whole Number Field

Here is the JavaScript for getting and setting the value of a Whole Number field (Display Name: “Number of Employees” | Database Name: “numberofemployees”):

//Get and Set a Whole Number field value
function WholeNumberFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var numberOfEmployeesFieldLogicalName = "numberofemployees";
    // Access the field on the form
    var numberOfEmployeesField = formContext.getAttribute(numberOfEmployeesFieldLogicalName);
    //Declare the other variables as needed
    var numberOfEmployeesFieldValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (numberOfEmployeesField != null) {
        // Get the value of the field
        numberOfEmployeesFieldValue = numberOfEmployeesField.getValue();

        // Set the value of the field
        numberOfEmployeesField.setValue(20000);
    }
}

Decimal Number

Here is an example of a Decimal Number field on a Dynamics 365 form:
Decimal Number field

Here is the JavaScript for getting and setting the value of a Decimal Number field (Display Name: “Exchange Rate” | Database Name: “exchangerate”):

//Get and Set a Decimal Number field value
function DecimalNumberFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var exchangeRateFieldLogicalName = "exchangerate";
    // Access the field on the form
    var exchangeRateField = formContext.getAttribute(exchangeRateFieldLogicalName);
    //Declare the other variables as needed
    var exchangeRateFieldValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (exchangeRateField != null) {
        // Get the value of the field
        exchangeRateFieldValue = exchangeRateField.getValue();

        // Set the value of the field
        exchangeRateField.setValue(1.35551);
    }
}

Floating Point Number

Here are some examples of Floating Number fields on a Dynamics 365 form:
Floating Number field

Here is the JavaScript for getting and setting the value of a Floating Number field (Display Name: “Address 1: Longitude” | Database Name: “address1_longitude”):

//Get and Set a Floating Point Number field value
function FloatingPointNumberFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var longitudeFieldLogicalName = "address1_longitude";
    // Access the field on the form
    var longitudeField = formContext.getAttribute(longitudeFieldLogicalName);
    //Declare the other variables as needed
    var longitudeFieldValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (longitudeField != null) {
        // Get the value of the field
        longitudeFieldValue = longitudeField.getValue();

        // Set the value of the field
        longitudeField.setValue(-79.387054);
    }
}

Currency

Here is an example of a Currency field on a Dynamics 365 form:
Currency field

Here is the JavaScript for getting and setting the value of a Currency field (Display Name: “Annual Revenue” | Database Name: “revenue”):

//Get and Set a Currency field value
function CurrencyFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var revenueFieldLogicalName = "revenue";
    // Access the field on the form
    var revenueField = formContext.getAttribute(revenueFieldLogicalName);
    //Declare the other variables as needed
    var revenueFieldValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (revenueField != null) {
        // Get the value of the field
        revenueFieldValue = revenueField.getValue();

        // Set the value of the field
        revenueField.setValue(52000000);
    }
}

Two Options

Here are some examples of Two Options fields on a Dynamics 365 form:
Two Options field

Here is the JavaScript for getting and setting the value of a Two Options field (Display Name: “Email” | Database Name: “donotemail”):

//Get and Set a Two Options field value
function TwoOptionsFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var dontAllowEmailsFieldLogicalName = "donotemail";
    // Access the field on the form
    var dontAllowEmailsField = formContext.getAttribute(dontAllowEmailsFieldLogicalName);
    //Declare the other variables as needed
    var dontAllowEmailsValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (dontAllowEmailsField != null) {
        // Get the value of the field
        dontAllowEmailsValue = dontAllowEmailsField.getValue();

        // Set the value of the field to TRUE
        //dontAllowEmailsField.setValue(true);

        // Set the value of the field to FALSE
        dontAllowEmailsField.setValue(false);
    }
}

Option Set

Here is an example of an Option Set field on a Dynamics 365 form:
Option Set field

Here is the JavaScript for getting and setting the value of an Option Set field (Display Name: “Contact Method” | Database Name: “preferredcontactmethodcode”):

//Get and Set a Option Set field value
function OptionsetFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var contactMethodFieldLogicalName = "preferredcontactmethodcode";
    // Access the field on the form
    var contactMethodField = formContext.getAttribute(contactMethodFieldLogicalName);
    //Declare the other variables as needed
    var contactMethodValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (contactMethodField != null) {
        // Get the value of the field
        contactMethodValue = contactMethodField.getValue();
        
        // Set the value of the field to FALSE
        contactMethodField.setValue(5);   
    }
}

MultiSelect Option Set

Here is an example of a MultiSelect Option Set field on a Dynamics 365 form:
MultiSelect Option Set field

Here is the JavaScript for getting and setting the values of a MultiSelect Option Set field (Display Name: “Geographical Areas of Operation” | Database Name: “hse_geographicalareasofoperation”) :

//Get and Set a MultiSelect Option Set field value
function MultiSelectOptionsetFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var locationFieldLogicalName = "hse_geographicalareasofoperation";
    // Access the field on the form
    var locationField = formContext.getAttribute(locationFieldLogicalName);
    //Declare the other variables as needed
    var locationValue;

    //Check that field exist on the form before you try to Get/Set its value
    if (locationField != null) {
        // Get the value of the field
        locationValue = locationField.getValue();

        // Set the value of the field to the desired values
        locationField.setValue([864700000, 864700003, 864700005, 864700007]);
    }
}

Date and Time

Here are some examples of Date and Time fields on a Dynamics 365 form:
Date and Time fields

Here is the JavaScript for getting and setting the value of a Date and Time field (Display Name: “Follow Up Date” | Database Name: “hse_followupdate”):

//Get and Set a Date and Time field value
function DateAndTimeFieldValue(executionContext) { 
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var createdOnFieldLogicalName = "createdon";
    var followUpFieldLogicalName = "hse_followupdate";
    // Access the fields on the form
    var createdOnField = formContext.getAttribute(createdOnFieldLogicalName);
    var followUpField = formContext.getAttribute(followUpFieldLogicalName);
    //Declare the other variables as needed
    var createdOnFieldValue;
    var followUpFieldValue = new Date();
    var numberOfDays = 30;
    var daysMillisecondsConverter = 24 * 60 * 60 * 1000;

    //Check that fields exist on the form before you try to Get/Set its values
    if (createdOnField != null && followUpField != null) {
        // Get the value of the field
        createdOnFieldValue = createdOnField.getValue();

        //Before you use the createdOnFieldValue value, verify that it exists
        if (createdOnFieldValue != null) { 
            //Set the follow up date to 30 days after the record was created
            followUpFieldValue.setTime(createdOnFieldValue.getTime() + (numberOfDays * daysMillisecondsConverter));           
            // Set the value of the field
            followUpField.setValue(followUpFieldValue);
        }        
    }
}

Lookup

Here is an example of a Lookup field on a Dynamics 365 form:
Lookup field

Here is the JavaScript for getting and setting the value of a Lookup field (Display Name: “Account Manager” | Database Name: “hse_accountmanager”) :

//Get and Set a Lookup field value
function LookupFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var accountmanagerLogicalName = "hse_accountmanager";
    // Access the field on the form
    var accountmanagerField = formContext.getAttribute(accountmanagerLogicalName);
    //Declare the other variables as needed
    var accountmanagerFieldValue;
    var guid;
    var name;
    var entityName;

    //Check that field exist on the form before you try to Get/Set its value
    if (accountmanagerField != null) {
        // Get the value of the field
        accountmanagerFieldValue = accountmanagerField.getValue();
        //Check if the field contains a value
        if (accountmanagerFieldValue != null) {
            //To get the attributes of the field
            guid = accountmanagerFieldValue[0].id.slice(1, -1);
            name = accountmanagerFieldValue[0].name;
            entityName = accountmanagerFieldValue[0].entityType;
        }

        // Set the value of the field
        accountmanagerField.setValue([{
            id: "4BDB64C8-AA81-E911-B80C-00155D380105",
            name: "Joshua Sinkamba",
            entityType: "systemuser"
        }]);

        //Alternative Approach: Set the value of the field
        //var lookupValue = new Array();
        //lookupValue[0] = new Object();
        //lookupValue[0].id = "4BDB64C8-AA81-E911-B80C-00155D380105";
        //lookupValue[0].name = "Joshua Sinkamba";
        //lookupValue[0].entityType = "systemuser";
        //accountmanagerField.setValue(lookupValue);
    }
}

Customer

Here is an example of a Customer field on a Dynamics 365 form:
Customer field

Here is the JavaScript for getting and setting the value of a Customer field (Display Name: “Main Customer” | Database Name: “hse_maincustomer”):

//Get and Set a Customer field value
function CustomerFieldValue(executionContext) {
    //Get the context of the form
    var formContext = executionContext.getFormContext();
    //The logical name of the field of interest
    var mainCustomerLogicalName = "hse_maincustomer";
    // Access the field on the form
    var mainCustomerField = formContext.getAttribute(mainCustomerLogicalName);
    //Declare the other variables as needed
    var mainCustomerFieldValue;
    var guid;
    var name;
    var entityName;

    //Check that field exist on the form before you try to Get/Set its value
    if (mainCustomerField != null) {
        // Get the value of the field
        mainCustomerFieldValue = mainCustomerField.getValue();
        //Check if the field contains a value
        if (mainCustomerFieldValue != null) {
            //To get the attributes of the field
            guid = mainCustomerFieldValue[0].id.slice(1, -1);
            name = mainCustomerFieldValue[0].name;
            entityName = mainCustomerFieldValue[0].entityType;
        }

        // Set the value of the field
        mainCustomerField.setValue([{
            id: "EE047399-CDE0-E911-B817-00155D380105",
            name: "Avanade",
            entityType: "account"
        }]);

        //Alternative Approach: Set the value of the field
        //var customerValue = new Array();
        //customerValue[0] = new Object();
        //customerValue[0].id = "EE047399-CDE0-E911-B817-00155D380105";
        //customerValue[0].name = "Avanade";
        //customerValue[0].entityType = "account";
        //mainCustomerField.setValue(customerValue);
    }
}