Sunday 29 August 2021

Files in Dynamics 365 CRM Part 2

 The last piece I worked on was to create the files in SharePoint and link them to the Document Location.

if you did not read part 1, kindly check it out here.

To create the file on SharePoint, I need two important requirements, the filename, and filecontent.

For Filename: You can access the file attribute from the FileAttachment entity. 

The output used in the filter array is the GUID of the file uploaded.

For FileContent:

SharePoint file creation

Because we have already linked the SharePoint to the right Document Location, the file created in SharePoint is visible in Document Location for that record

Files in Dynamics 365 Part 1

 I recently worked on a project that involved handling files with SharePoint and Dynamics 365 CRM. While all the scenarios are connected, it took me a few days to get the output I desired, so I decided to do a little safe-keeping by blogging it.

The scenarios

  1. Stop default SharePoint Document Location creation in Dynamics 365 CRM and create a custom document location
  2. Upload Files into Dynamics 365 CRM using the File Data Type
  3. File uploaded in No 2. should be created in the SharePoint Folder for the associated record and also linked to the associated Document Location.
Let's dig in

Stop default SharePoint Document Location creation in Dynamics 365 CRM and create a custom document location

This was achieved in two parts (using a Real-time workflow and Power Automate )

First Part

Real-Time workflow was used to disable the default document location that is created when the "File" tab of the associated record is clicked.

The workflow is created on "Document Location" entity. I simply added a condition that states:
and added a step to cancel the creation

Note: The flow cancels default document location creation for the entities in the condition.

Second Part:

I created a 5 step Power Automate and the final output is this:

Let's break it down (The custom document location is created for opportunity)
  • Step 1:  

  • Step 2: I filtered the rows to return using the Odata query. 
    name eq 'Documents on Default Site 1' and _regardingobjectid_value eq null and relativeurl eq 'opportunity'
    Note: The "relativeurl" changes depending on the entity and a "Documents on Default Site 1" has been created for the opportunity as a Document Location in Dynamics CRM

  • Step 3: 

  • Step 4:  I used an "OData.Id" from Step 3. 
  • Step 5: The "ODataId" is from Step 4
  • Final Result:

Upload Files into Dynamics 365 CRM using the File Data Type

This is quite straightforward. A file datatype control was added to the form and I was able to upload files. Questions around where the files are stored may arise which is not clear now, but I am still researching this.

Sunday 5 July 2020

Consume Microsoft Dynamics NAV/BC ODATA using .NET C#

I meddled into consuming NAV Odata using C# this evening.

The walkthrough followed as documented by Microsoft: Walkthrough: Creating and Interacting with a Page Web Service (OData)

I had made some changes as my request is quite different and below is what I did:

Tools Used

  1. VS 2017
  2. OData Connected Service.
    1. Download from here: OData Connected Service OR
    2. Download from VS => Tools => Extension and Updates => Search for OData Connected Service.
  • Expose the Odata URL/endpoint on NAV/BC
  • Get Authorization Code: I used Postman to get this.

  • Create Console Application on VS2017
  • Add Connected Service to the project
  • Enter Service Name, Address, Authorization header

  • Use the necessary references and namespace of the service

  • See code sample

using System;using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using NAV;
namespace NAVConsole
class Program
static void Main(string[] args)
String username = "Test";
String password = "your password";
NAV.NAV nav = new NAV.NAV(new Uri("http://<servercomputer>:<odataport>/<serverinstance>/ODataV4/Company('PILOT')"));
nav.Credentials = new NetworkCredential(username, password);
private static void PrintSalaryAdvances(NAV.NAV nav)
var salAdv = from s in nav.StockAutomationCard
select s;
foreach (var item in salAdv.ToList())
Console.WriteLine($"Requester: {item.User_ID}, No: {item.No}");

  • Result

Saturday 4 July 2020

Start workflow from button in Microsoft Dynamics CE.

Executing workflow from the ribbon button in the days of the Classic Interface of Dynamics CRM/CE requires a mix of the JavaScript and workflow.

But with the advent of Smart Buttons by Scott Durrow, things are a lot easier and compatible with Dynamic CE unified interface.

Here is the link that explains the features and usage:  Smart Buttons for Unified Interface
Here is the link to download and install the SmartButton solution: SmartButtons Solution

Enjoy ✌

Wednesday 1 July 2020

Show/Hide button based on security role using Entity Privilege on Microsoft Dynamics CE

I came across this request sometimes ago but I implemented it using code: JavaScript. Nevertheless, my client still experienced issues because the button is not visible at certain times.

So I had to search for another solution: using Entity Privilege. This is simple and it works well.

The steps are below. These steps are grouped into two

  1. On the Ribbon WorkBench Tool (RWB Tool)
  2. On Dynamics 365/CRM: Entity and Security Customization
My scenario is to show Procure button on quote entity when quote status is Won for a user with Procurement Officer or Procurement Admin Role

On Dynamics: Entity and Solution Creation

  • Create an entity. e.g. button access
  • Add the new entity (button access) and other entities you want to work on in the RB Tool to a solution

On RWB Tool

  • Open Ribbon Work Bench tool (RB Tool) and select your solution
  • Right-click the button and choose "customize command"

  • Display Rule: Add an EntityPrivilegeRule, 
    • Set Default to True
    • EntityName to the new entity created (button access)
    • PrivilegeDepth to Basic
    • PrivilegeType to Create or anyone you wish

  • Add Display Rule to Command

  • Publish your ribbon customization.

On Dynamics: Security 

  • Open Security role and select anyone you want to edit
  • Select Custom entities and locate the new entity (button access)
  • Give User/Basic Privilege as shown in the image below
  • Procure Button on Quote entity.

Entity mapping for fields in Microsoft Dynamics CE

Customizing entities is a norm when you extend in Dynamics CRM. I came across entity mapping twice so I decided to blog this as a reference to me and any other finding solution.

It quite easy to map attributes in entities with visible relationships in Dynamics CRM but for hidden relationships, you have to go through some steps to map these custom fields/attributes

Prerequisites before mapping:

Ensure there is an existing relationship between the entities and get the Mapping ID: You can confirm through

Get EntityMap Id

  • Get All Entity Maps: This displays a list of all mapping existing in your environment. 
[Organization URI]/api/data/v9.0/entitymaps?$select=sourceentityname,


  • Get a Specific Entity Map: Between SalesOrderDetail and InvoiceDetail
[Organization URI]/XRMServices/2011/OrganizationData.svc/EntityMapSet?$
select=EntityMapId&$filter=SourceEntityName eq "salesorderdetail" and
TargetEntityName eq "invoicedetail"
The EntityMapId will be the same

Create Mapping

Use the entitymapid
[Organization URI]/Tools/SystemCustomization/Relationships/Mappings/

Thursday 6 December 2018

Build Numbers for Dynamics CRM

I was tasked to get all the build numbers for every version of Microsoft Dynamics CRM version released which made me curious as to why I had not documented it.

My research brought me to this page. A comprehensive list of all build numbers of Microsoft Dynamics CRM.

Click Build Numbers for Microsoft Dynamics CRM to get it.