Advertisements

Archive

Archive for the ‘Dynamics 365’ Category

IntelliSense in Jscript/TypeScript file – Dynamics 365

In this article, lets see how to configure intellisence with XRM syntaxes in your Jscript/TypeScript files.

To enable IntelliSence, you need to install xrm npm package to your Visual Studio.

Steps to install NPM package:

  • To install npm package, you need to download and install a Visual Studio extension : Package Installer

Intelli - 5

  • Post installation, from your Visual Studio, select ‘Quick Install Package’ from Menu

Intelli - 6

  • From the popup,
    • Select ‘npm’ in the dropdown
    • In the textbox, type ‘@types/xrm
    • Click on ‘Install’

Intelli - 7

  • Post package installation, refresh the project and you should see a new folder ‘node_modules
    • Note: If you dont get the ‘node_modules’ folder, check your project’s physical location and add the folder to your Visual Studio project.

Intelli - 8

  • In above screen, ‘TypeScript’ is my project name and post above steps, I got the ‘node_modules’ project.

Enable IntelliSence in your Jscript/TypeScript file:

  • Open your script file
  • Drag and drop the ‘index.d.ts’ file from ‘node_modules’ folder on to your script file.
    • Alternatively you can also this syntax
      • /// <reference path=“../node_modules/@types/xrm/index.d.ts />

Intelli - 1

  • Start typing ‘Xrm’ and you should see the syntaxes.

Notes:

  • Those who are wondering what is a npm, it is a package manager for the JavaScript programming language.
  • www.npmjs.com hosts thousands of free packages to download and use.

 

Advertisements

Dynamics CE – Demystify ‘Auto Number’

Auto Number‘ feature is available with Dynamics 365 (online) and V9.x versions. With this feature we are no longer dependent on 3rd party ISV solutions for Auto numbering.

Auto Number - 2

In this article I am going to cover a few use cases of Auto Number fields.

How to create an Auto Number field:

As of the date, we can either create a new ‘Auto number’ field or convert an existing field to ‘Auto Number’ only programmatically (i.e., using SDK call).

Creation of an ‘Auto Number’ from Application will be included in next releases.

Lets see how to create a brand new ‘Auto Number’ field and convert an existing ‘Single Line Of Text’ field to ‘Auto Number’ along with few key points.

[Code Snippet] Create a NEW auto number field:

Below is the sample code to create a new Auto Number field ‘new_studentnumber‘ in a custom entity ‘new_student

var studentNumberAttributeRequest = new CreateAttributeRequest{
EntityName = “new_student“,
Attribute = new StringAttributeMetadata{
//Define the format of the attribute
AutoNumberFormat = “STD-{SEQNUM:4}”,
// Set fields Logical and Schema Name
LogicalName = “new_studentnumber“,
SchemaName = “new_studentnumber“,
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
MaxLength = 100,
// Set fields Display Name and Description
DisplayName = new Label(“Student ID”, 1033),
Description = new Label(“Student ID”, 1033)
}
};
_serviceProxy.Execute(studentNumberAttributeRequest);

  • Make sure you ‘Publish‘ customization’s from Application after executing the code.

[Code Snippet] Convert EXISTING field to an auto number field:

Below is the sample code to convert OOB ‘new_name’ field to auto number field in the custom entity ‘new_student‘.

Important note:

  • Field you are converting has to be of type ‘Single Line Of Text’.
  • If you pass a different type of field (Ex- Whole number), code will not throw any exception but no auto number logic will get attached to the field.

// First retrieve the Attribute Metadata
var attributeRequest = new RetrieveAttributeRequest{
EntityLogicalName = “new_student”,
// Pass the attribute name
LogicalName = “new_name”,
RetrieveAsIfPublished = true
};

// Retrieve attribute response
var attributeResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(attributeRequest);

// Now modify the retrieved auto-number attribute
var retrievedAttributeMetadata = attributeResponse.AttributeMetadata;
// Set the auto numbering format
retrievedAttributeMetadata.AutoNumberFormat = “STD-{SEQNUM:3}-{RANDSTRING:6}”;

// Update the auto-number attribute
var updateRequest = new UpdateAttributeRequest{
Attribute = retrievedAttributeMetadata,
EntityName = “new_student”,
};

// Execute the request
_serviceProxy.Execute(updateRequest);

  • Make sure you ‘Publish‘ customization’s from Application after executing the code.

Key Points:

  • Auto number fields will be Read-only and you cannot override the value from Form.
  • But you can override the value from code using SDK Insert call.
  • As you would notice below, Even though the ‘Name’ is an Auto number field, I could create a ‘Student’ record from code by setting ‘Name’ to ‘Rajeev’.  If you dont set a ‘Name’ field value from code, system would populate the auto number.

Auto Number - 1

  • In a single Entity, you can have multiple auto number type fields with the same format.
  • You can alter the auto number format of a field at any point of time by using ‘UpdateAttributeRequest’ SDK call (Refer 2nd code snippet above).
  • In the Auto number format, use ‘Random String’ tag (i.e., {RANDSTRING:number}) which help you to avoid duplicates or collisions, especially when offline clients trying to create auto-numbers.
    • For example, CNR-{RANDSTRING:4} format will generate an auto number with a random string of 4 character length (i.e., ‘CNR-WXYZ‘)

Auto Number - 3

  • The random string placeholders are optional.You can include more than one random string placeholder in an Auto Number Format.

🙂

 

Dynamics Portals – ‘Record Mover’ and ‘Code Editor’ Tools – XrmToolBox

If you are a Dynamics Portal developer, couple of pain points you would have experienced, are

  • Moving configurations from environment to other
  • Navigating among multiple screens (Web Pages/Templates/Files etc…) to edit the configurations.

Lets see how these are addressed with below tools from our favorite XrmToolBox

  • Portal Records Mover
  • Portal Code Editor

Portal tools

Portal Records Mover:

To move the Portal configurations from environment to another, you might have used OOB “Configuration Migration Utility” tool but this tool has limitation as listed below.

  • You cannot choose records (For example, only specific Web Templates) as it would export all records for chosen entities.

With the ‘Portal Records Mover tool, now you can pick the sub set of records from Portal entities and you can apply Date filters and many more.

Usage steps:

  • From your XrmToolBox, connect to Portal Records Mover tool to your Dynamics instance.
  • Click on ‘Load Items’ , which load all Portal related entities.
  • From the “Options” tab,
    • Apply Date filters, if you want
    • Pick the ‘Web Site’, if you have multiple Portals (Custom Portal/Dealer Portal/etc..) installed

Export Records:

  • Choose the Portal Entities from left pane, you would like to migrate records from.
  • Click ‘Retrieve record’, to load the records from selected Portal entities.
  • Pick the records, you would like to migrate.

Portal Mover

  • Once you completed the record selection, click on “Export Records”
  • Choose the location to save the XML file.

Portal Mover - 2

  • XML file contain the records you selected.

Portal Mover - 3

Import Records:

  • To import the portal configuration to a Dynamics instance, you must have the XML prepared as mentioned above.
  • Click ‘Import records’ button and provide the portal configurations XML file.

Portal Mover - 4

Portal Code Editor:

This tool provides an easy way to edit all your Portal configurations in one place.

Note: This tool only works for Dynamics Portals and does not support ADX portals.

Usage steps:

  • Connect to Portal Code Editor tool to your Dynamics instance.
  • Click on ‘Load Items’ , which load all Portal related entities group by categories (i.e., Web Pages/Entity Forms/…).
  • Pick the record you want to update.
  • Modify the content and click ‘Save’ from ‘File’ menu.

Portal Code Editor

  • ‘Save’ just saves the content in Editor
  • To apply changes to your Dynamics instance, click on ‘Apply change to portal’ button

Portal Code Editor 2

Note:

  • Make sure you have the latest XrmToolBox downloaded, if you don’t find these tools.

Thanks to Tanguy TOUZARD for these amazing tools.

🙂

 

 

Dynamics 365 – Configure ‘Relevance Search’

In Dynamics 365 online we have 2 types of Global Search

  • Category Search
  • Relevance Search

Rel Search_8

Category Search:

  • Its a multi-entity Quick Find Search, where you can pull the matching records from all configured entities in a single screen.

Relevance Search:

  • Relevance Search delivers fast and comprehensive results across multiple entities in a single list, sorted by relevance.
  • It uses a dedicated search service external to Dynamics 365 (powered by Azure) to boost Dynamics 365 search performance.

Lets see how to configure ‘Relevance Search’ in Dynamics instance and enable an entity.

Enable Relevance Search:

  • You have to enable Relevance Search first, Go to Settings -> Administration -> Check the ‘Enable Relevance Search’ checkbox

Rel Search_1

Set Entities Managed Property:

  • To enable entity for ‘Relevance Search’, make sure Managed property set to ‘True’. This property will be ‘True’ by default.

Rel Search_2

Add Entity to the list:

  • Open the ‘Default Solution’ -> Configure Relevance Search
  • Add the entity to the list

Rel Search_3

Set default global search:

  • You can choose the default search between ‘Categorized Search’ and ‘Relevance Search’ from your ‘Personal Settings’.
  • Last search option provides the last search experience you used in the current browser client. For example, if you used Relevance Search for your last search, the system will continue using this search until you manually switch to Categorized Search.

Rel Search_6

Notes:

  • ‘Relevance Search’ is only available in Dynamics 365 online.
  • ‘Relevance Search’ is text-based, and can search only on fields of type Single Line of Text, Multiple Lines of Text, Option Sets, or Lookups. It doesn’t support searching in fields of Numeric or Date data type.
  • You can use syntax to search with combinations. For example, type car+silver+2-door to find only matches that include all three words. Type car|silver|2-door to get results that contain car or silver or 2-door, or all three words
  • There is no limit on no of entities can be included in the Relevance Search results. However, there is a limit on the total number of fields in the external search index. Currently, the maximum is 1000 searchable fields for an organization.

🙂

[Step By Step] Configure Server-to-Server (S2S) authentication using Azure AD and Application User – Dynamics 365

In this article I am going to explain, what is ‘Application User’ and how it helps to establish using Server-to-Server (S2S) authentication and Azure Active Directory

To explain the S2S authentication simpler, let’s take an integration requirement

  • You have an ASP.Net Web Application
  • You need pull the Contacts from a CRM organization and display in the ASP.Net Web Page

The conventional design approach for the above requirement would be

  • Establish the CRM connection in your ASP.Net page by passing CRM User credentials
  • Make a Retrieve call to CRM
  • Read and bind the Contacts to a grid.

To implement the above design you need to have a paid CRM User credentials to interact with your Dynamics CRM organization.

So what is S2S authentication and how is it different from the legacy integration model we discussed above.

Server-to-Server (S2S) authentication:

  • S2S authentication means you don’t need to use a paid Dynamics 365 user license when you connect to Dynamics 365 tenants.
  • We will use a special user (i.e., Application User)
  • Best part is, you can connect to D365 and make server calls from your application (i.e.,Web/Console) with no Dynamics SDK dlls and no ‘UserID/Password’.

What is this ‘Application User’:

  • ‘Application User’ is a ‘systemuser’ record of type ‘Application User’
  • There is no license fee for the ‘Application User’ account

App User - 14

How an ‘Application User’ account achieve the S2S authentication:

  •  ‘Application User’ with conjunction of Azure Active Directory (Azure AD) will establish S2S authentication.
  • We first generates an ‘Application ID’ in Azure AD which we set in ‘Application User’ in Dynamics.

Lets see the step by step approach to achieve S2S authentication.

  • Pre-requisites:
    • Dynamics 365 instance
    • Azure Subscription with same Office 365 account used for your D365 instance.
  • High Level Steps
    • Generate ‘Application ID’ and ‘Keys’ in ‘Azure’
    • Add a new User in ‘Azure Active Directory’ (Azure AD)
    • Create a new ‘Application User’ in Dynamics 365

Step 1 – Generate ‘Application ID’ and ‘Keys’ in ‘Azure’:

  • Connect to your Azure
  • Go to ‘App registrations’ service

App User - 1

  • Create a ‘New application registration’
    • Note: ‘Sign-on URL’ can be any valid URL.

App User - 2

  • Copy the generated ‘Application ID’ (This is needed while creating ‘Application User’ in CRM)

App User - 3

  • Generate ‘Keys’ (You need the ‘Key’ to establish connection in your Web Application/Console Application)

App User - 4

  • Save the ‘Key’ (Note: You cannot read the key if you move away from the screen)

App User - 5

Step 2 – Add a new User in ‘Azure Active Directory’ (Azure AD):

  • Connect to your Azure
  • Go to ‘Users’ service

App User - 6

  • Create a ‘New User’
    • Note: ‘Password’ auto generates once you save. You don’t need to copy as this is not required further.

App User - 7

  • Once the User saved, copy the ‘User Name’ (This is needed while creating ‘Application User’ in CRM)

App User - 8

Step 3 – Create a new ‘Application User’ in Dynamics 365:

This step we are going to create an ‘Application User’ in D365 by copying the details generated in Azure

  • Connect to Dynamics 365
  • Go to ‘Settings -> Security -> Users
  • Switch the view to ‘Application Users’ and click ‘New’

App User - 9

  • In the ‘New User’ screen
    • Set ‘User Name’ with the ‘User Name’ copied from ‘Azure’
    • Set ‘Application ID’ with the ‘Application ID’ copied from ‘Azure’
    • Save the User and once saved, you notice the auto populated ‘Application ID URI’ and ‘Azure AD Object ID’

App User - 10

  • Assign a ‘Security Role’
    • ‘Security Role’ must be a Custom Security Role and you cannot assign OOB role.
    • For this exercise, you might want to copy any existing OOB Security Role.

All right! We are all set and now its time to test S2S authentication from your console.

S2S Authentication Code Snippet:

Prerequisites:

  • Install ‘ADAL’ and ‘NewtonSoft’ NuGet packages

 Code:

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
private static async Task GetContactsAsync()
{
// Your Dynamics Web API URL
string api = “https://docmigrate.api.crm.dynamics.com/api/data/v9.0/&#8221;;

AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(api)).Result;

// Set ‘Application ID’ and ‘Key’ generated from Azure
var creds = new ClientCredential(“e4ac3a78-xxxx-403a-a94c-xxxxxxx”, “hEo/xxxxxxxS+LEiYHpxxxxxxxRe8xg0=”);

AuthenticationContext authContext = new AuthenticationContext(ap.Authority);
var token = authContext.AcquireTokenAsync(ap.Resource, creds).Result.AccessToken;

using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Bearer”, token);

// Retrieve Top 1 Contact
HttpResponseMessage response = await httpClient.GetAsync(api + “/contacts?$top=1”);

// Parse the response
if (response.IsSuccessStatusCode)
{
JObject contact = JsonConvert.DeserializeObject<JObject>(await response.Content.ReadAsStringAsync());

var contactName = contact.GetValue(“fullname”);

}
}
}

App User - 13

🙂

Dynamics 365 Spring Release 2018

Microsoft has released Spring ’18 release notes for Microsoft Business Applications and can be downloaded from here

D365_Spring_18

Refer this link for all latest updates on Dynamics 365

Dynamics 365 – Create/Modify Views using App Designer

In this article, I am going to detail, how views can be created or modified using App Designer.

Open ‘App Designer’:

  • To start off, go to ‘My Apps’ by navigating to ‘Settings –> Application –> My Apps’

Views - 1.PNG

  • Open the ‘Sales’ app in ‘App Designer’ by clicking ‘OPEN IN APP DESIGNER’

Views - 2

Add/Edit Views:

Once the ‘App Designer’ loads, lets see how to modify Account’s ‘Active Accounts’ view

  • From the ‘App Designer’ window, under ‘Entity View’ section, select the ‘Views’ tab from ‘Account’ row.
  • On the right side ‘Public Views’ tab, select the View you want to modify (i.e., ‘Active Accounts’ in my case)
  • After selecting the view from right window, back to ‘Views’ tab and expand, open the ‘Active Accounts’ to Edit

Views - 3

  • To add new column, click on ‘Add’ button, choose Primary or Related entity to add the fields from and drag and Drop the column you want.

Views - 4

  • Expand the ‘Filter Criteria’ tab to update the filter

Views - 5

  • To add new view, click ‘Create New’ from your ‘App Designer’

Views - 6

With the ‘App Designer’, you can perform all the view customizations, which you can do with conventional view editor.

Refer article  for more details.

🙂