Identify Users with System Administrator privileges using Dynamics 365 SDK

CRM does not seem to provide any methods in the SDK to check if a user has System Administrator privilege’s.

One straightforward way to achieve this is to query for a roles associated with the user which has a title of ‘System Administrator’. However this approach has its limitations in a multi-language enabled tenant as the role title would have been defined in a different language, in which case querying for a role with the tile ‘System Administrator’ would not render any results.

Looks like there is a possible undocumented way to get around this limitation.

Every OOB CRM role seems to have a ‘Role Template’ associated.
So the ‘System Administrator’ role is associated with a role template with the id ‘627090FF-40A3-4053-8790-584EDC5BE201’.
This role template id is the same across all tenants and is set when the instance is provisioned.

This id can be used to query CRM and get the desired results.

Refer sample query below. If the below query returns any record we could safely assume that the user has ‘System Administrator’ privilege.

var roleQuery = new QueryExpression(“role”);
roleQuery.Criteria.AddCondition(“roletemplateid”, ConditionOperator.Equal, “627090FF-40A3-4053-8790-584EDC5BE201”);
var userRolesLink = roleQuery.AddLink(“systemuserroles”, “roleid”, “roleid”);
userRolesLink.LinkCriteria.AddCondition(“systemuserid”, ConditionOperator.Equal, [USER GUID]);

_dynamicsService.RetrieveMultiple(roleQuery);

PDF Document Generation Updates in Dynamics 365 2020 Wave 2 Release

If you are new to PDF document generation in CRM refer my previous introduction blog. The latest 2020 Wave 2 update introduces some interesting updates to this feature.

1. PDF generation capability is now enabled for all the entities (system & custom)

On the Sales Hub app navigate to App Settings -> Productivity Tools where you will find the whole list of entities on which the feature can be enabled.

2.  The button has been renamed to ‘Export to PDF’.

Document generation works only for 1 record at a time and at the moment the button is only available on the Entity Form.
With a bit of ribbon customizations, we should be able to get this button the GRID as well, but it would work only for 1 record at a time

3. Clicking the button opens the below window with a much-improved user experience.

4. The PDF generation capability is now exposed as an Action and can now be called via the API as well

Here’s a sample code to generate a PDF document for an invoice template using C#

OrganizationRequest Req = new OrganizationRequest(“ExportPdfDocument”);
Req[“EntityTypeCode”] = 1090;
Req[“SelectedTemplate”] = new EntityReference(“documenttemplate”, new Guid(“ea22f936-1033-41dc-9349-cfcffbeee4c8”));  
List<Guid> invoiceRecords = new List<Guid> { new Guid(“66d57d7e-e142-4313-8f2b-15b82a685771”) };
Req[“SelectedRecords”] = JsonConvert.SerializeObject(invoiceRecords);
OrganizationResponse Response = dynamicsService.Execute(Req);


The response object should provide you the pdf document as a byte array.

Note: Although the ‘SelectedRecords’ property accepts an array, it works only for the 1st record when you pass in multiple values.


Import Excel/CSV from Sub Grid within Dynamics 365

Dynamics 365 allows bulk import of data from an Excel/CSV file.  This option is easily accessible on Home Grid for both system and custom entities.

However many a times, some entities may never have a Home Grid. i.e.: Some entities may actually be a child of some parent entity and may end up only being displayed as a Sub Grid on the parent entity record.

Dynamics 365 does not provide the Import options on the Sub Grid.  Fortunately, its possible to customize the Sub Grid to add a custom button and invoke the OOB import functionality.

Use the ‘Ribbon Workbench’ tool to add a new button on the entity Sub Grid.
In the below example I have an ‘Import from Excel’ button on the entity sub grid. Since we are invoking the OOB Import Excel functionality there is no need to create any custom command.
Simply populate the ‘CommandCore’ property with ‘Mscrm.ImportDataFromExcel’ and you good to go.
Set the ‘CommandCore’ property to ‘Mscrm.ImportDataFromCSV’ if you plan to use the CSV approach

Here is how the button looks on the actual sub grid

Understanding Dynamics CRM Form Header

The Form Header usually consists of the below components

  1. Record Title
  2. Record Image
  3. Form Switcher (if case of multiple forms)
  4. Fields

Additionally, one can also configure the Header to display a custom Web Resource OR an I-Frame.

The Form Header can include many fields, however only the 1st 4 fields would be directly visible on the Header and the rest would be available on the Header Flyout menu which can be accessed by clicking the chevron on the extreme right. All the fields can be set to editable or read-only from within customization.

Screenshot of the Form Header

Screenshot of the Form Header Flyout

The above header concept was referred to as ‘Header Tiles’ and had it had a couple of issues.

  1. The Record Title was automatically truncated if it exceeded a certain length
  2. The fields were spaced widely resulting in a lot of white space.

The recent 2019 Wave 2 release introduced the concept of the High-Density Form Headers to tackle the above issues.
Note: High Density Forms can be enabled/disabled only thru PowerApps. (https://make.powerapps.com)

Once ‘High Density’ is enabled, here is how the new Header looks like

Screenshot of the Form Header

  1. The Record Title is now allowed to span its length and get automatically wrapped to the next line if needed.
  2. Only the 1st 4 fields are directly visible on the Header and are now rendered in read-only mode to converse white space.
  3. The Form switcher control is now below the Record Title

Once ‘High Density’ is enabled, you also have an additional option to enable the ‘Header Flyout’ menu.

Once ‘Header Flyout’ menu is enabled, clicking the chevron to the extreme right displays the Header Flyout menu. All fields configured on the Header are available in the Flyout menu and can be made editable or read-only individually from within the customization section. (refer screenshot below)

Dynamics CRM Error Codes

When Dynamics CRM encounters any error it usually does a great job of providing additional details on the issue. However, there could be instances when CRM is not so friendly. In some scenarios it just throws up an error code without any description.

In such cases, it gets tricky to resolve the issue as the issue itself is unknown.

Below is one such scenario I recently ran into while trying to import records using the OOB Data Import Tool.

The issue occurred during the Transform phase,
The failed record on the Import job had an error code, however the was no error description available.

On googling the issue further, I landed on the Microsoft official documentation for error codes which had details on the issue.

Below is the link which documents the various error codes within Dynamics CRM.

 https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/org-service/web-service-error-codes

Happy Troubleshooting !!

Ribbon Button Troubleshooting Guide

If you ever run into issues with Ribbon Buttons (with regards to visibility or click events) on Dynamics CRM, try the link below.
Apparently Microsoft has a inbuilt Troubleshooting wizard within Dynamics CRM to identify the various issues with Ribbon Buttons.
Follow the steps in the link and hopefully you should get your button working again.

https://support.microsoft.com/en-in/help/4552163/ribbon-troubleshooting-guide

Note : This guide only applies to Ribbon button issues on the Unified Interface

Create PDF Document from Dynamics 365

Dynamics 365 offers several options to generate documents. This could be for emailing a Quote to a customer OR to print an Order or Invoice.
Most of the time documents needed to be generated in PDF format.

Below are some of the common options available within Dynamics 365 for Document Generation

1. Mail Merge
A good old functionality existing since CRM 2011 which could generate a word document, however is soon set to be retired.
Refer link https://docs.microsoft.com/en-us/dynamics365/get-started/whats-new/customer-engagement/important-changes-coming

2. Reports
This was one of the preferred ways to generate documents, however it involved mutiple manual steps for users in order to run the report and to convert it to a document. However creating reports may involve development efforts depending on the complexity of the report, but the advantage here was that reports could output data in multiple formats (Word, Excel, CSV and even PDF)

3. Document Templates
Introduced in CRM 2016, this could generate a word document with a single click and soon became the popular choice for document generation.  However this OOB functionality could only generate documents in Word format.

Other than the above various ISV’s offered their own custom solutions, which could output documents in various formats.

All the above OOB solutions either involved multiple steps from the users end to generate the document OR involved investment on a 3rd party add-on which could do the same job in a couple of clicks.

In order to address this limitation, Microsoft introduced automatic PDF generation from a Quote record with ver. 9.0.1905.2010 of the Sales App.
Note : The feature is currently available only for UCI.

The feature needs to be enabled in order to be used.

To enable PDF generation via Quote, browse to ‘App Settings’ area within ‘Sales Hub’
Within this area, under ‘Sales Administration’, you should find the ‘PDF Generation’ setting.
Set it to ‘Enabled’
Note : In some CRM instances the location may slightly differ based on the sitemap customization, but it should be located somewhere within the ‘Sales Hub’ app.

Now browse to a quote record and you should find the 2 new buttons (‘Create PDF’ & ‘Email as PDF’) available on the Ribbon

Clicking on the button list down the various documents which can be generated.
The documents listed here are the various Document Templates defined within the system.
Note: When a new Document Template is created is CRM (for Quotes), it would be automatically available under both of these options.

These buttons do exactly what the say.
Create PDF: Automatically creates a PDF document for the selected Document Template and opens it up on the screen.
Email as PDF: Open up a draft Email record with From, To, Subject & Regarding fields auto populated and the PDF document attached. Users would need to manually make are necessary changes to the Email and hit the ‘Send’ button to send the Email.  

At the moment, PDF generation feature seems to be limited only for the Quote entity.
However we hope that this functionality would be gradually extended to other entities in the future releases of CRM.

Additionally exposing PDF document generation capabilities via the CRM SDK would be a dream come true

Update:
The PDF generation capability for additional entities (entities other than Quote) is released with Dynamics 365 Sales (Sales Hub) app version: 9.0.1911.1009

Below are the list of entities which currently support PDF generation.

.

Importing Multi-Select Picklist data in Dynamics 365

Multi-select picklist was one of the most requested features in the Dynamics community and was introduced in Dynamics 365 from ver. 9.0

However, importing multi-select picklist data can be a problem using the CRM Import Tool. Below is the sample csv file with a multi-select column named ‘Hobbies’.

Although it as 2 distinct values in the ‘Hobbies’ column (data in multi-select field supposed to separated via semicolon), the CRM Import Tool does not consider the same. Refer screenshot below.

Importing the above will result in CRM automatically creating a new option set value called ‘Running; Swimming’ which is not the intended purpose.

Now the good news:
The CRM Import Tool supports both CREATE and UPDATE of records. Although the tool does not support multi-select picklist data during record creation, it does support multi-select picklist data during update of records.

On the CSV file which you plan to import (for record creation) add a new column (e.g.: Unique Id) and populate it with a sequential number value.

Create a similar field in CRM (datatype: whole number) on the entity.
While mapping the columns during Data Import ensure the map the ‘Unique ID’ column with the newly created field.
Do the map the Multi-select field. (We will be handling this after the import)
Now proceed with the Import. Once successfully imported, you should have all the records created in CRM with the ‘Unique ID’ field.

Include the ‘Unique ID’ field and the Multi-select field in a new view and sort it based on the ‘Unique ID’. Now export the view to Excel as a ‘Static worksheet’.

You now have 2 files:

  • Original import file
  • Exported data file from CRM

Ensure that the data in both files have been sorted by the Unique ID field. Carefully copy the multiselect column data from the original file and paste it over the multiselect column on the file exported from CRM. (Do not overwrite the header column)

Simply import back the updated file using the CRM Import Tool. CRM will identify it as a update job and update back all the records in CRM with the multi-select values.

Alternatively, you could even use the ‘Open in Excel Online’ feature to do the same.

Below are some of the other Limitations to be aware of:

  • Default value for a multi-select picklist cannot be set from within Customizations; however, you could use custom code approach to set a default value.
  • You could define any number of options for a multi-select picklist, however only a maximum 150 options can be selected for a multi-select picklist field
  • Although multi-select picklist is available as a ‘Trigger’ for workflows, it cannot be used within a ‘Check Condition’ on a Step.
  • Bulk-Edit does not support multi-select picklist fields.
  • If you plan to use the CRM SDK to create/update multi-select picklist values ensure that you are using the ver. 9 or above of the SDK assemblies.

More details on how to interact with multi-select picklist via CRM SDK here

Retrieve the SharePoint Document location URL using CRM SDK

The ‘SharePoint Document Location’ entity record in CRM is the link between the CRM record and the actual document uploaded within SharePoint.
For every document uploaded in SharePoint (from within CRM) there could be 1 or multiple ‘Document Location’ records created in CRM, depending on the SharePoint folder structure configured within ‘Document Management’ Settings.

The actual SharePoint location URL is not available in any of the ‘Document Location’ records, instead CRM automatically generates the URL based on these records.

Fortunately, CRM does provide an easy way to access the URL via SDK.
The sample code below retrieves the full URL for any SharePoint document

RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest{
Target = new EntityReference(“sharepointdocumentlocation”, [SharepointDocumentLocationId])    };
RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)organizationProxy.Execute(retrieveRequest);
string siteCollectionUrl = retriveResponse.SiteCollectionUrl;
string absoluteUrl = retriveResponse.AbsoluteUrl;

Site Collection URL: URL of the SharePoint site associated with CRM
Absolute URL: The full URL path of the folder/document within SharePoint

Update CRM Portal Sign In Link/Button

CRM Portal provides various ways to authenticate a User. This includes Local Login and various other Federated Login options. Depending on requirements one can enable any or all the login options.

By default, clicking on the Portal ‘Sign In’ link on the homepage, the user is redirected to an inbuilt login page where one can login using Local Login or any Federated Login (if enabled) (refer screenshot below)

portal login screen

Each Federated Login option is displayed as a button on the right hand side.

Having multiple Login options, definitely has its advantages however there could be situation wherein the Portal may have been enabled for only 1 External/Federated Login. In such a situation it would not be a good user experience to have to user browse to the above login page and then click the appropriate button which would then take him to the Login page for the Federation provider

Although there is no customization option within the Portal, to customize the ‘Sign In’ link on the Portal homepage, the Portal does provide a configuration option to redirect the user directly to the Federation Provider’s Login page.

To enable this go to Portal – Site Setting and create new record with the name
“Authentication/Registration/LoginButtonAuthenticationType”
Value should be set to the URL of the Federation Provider

For more details on the above setting click here