Advertisements

Archive

Archive for the ‘Dynamics 365’ Category

[Step by step] Postman tool to test Dynamics 365 online Web API

February 13, 2019 Leave a comment

In this article, lets see how to connect and test Dynamics 365 Web API requests using Postman tool, step by step along with troubleshooting steps.

Those who are not familiar with Postman tool, it is a request composer tool, which allows you to authenticate to your Dynamics 365 instance,  compose Web API requests, send them, and view response. Link to download

Prerequisites:

  • Download Postman tool
  • Dynamics 365 online instance. (Subscribe to 30 days trial, if you have not one)
  • Azure Active Directory Portal (You need to login with your Office 365 Credentials)

Register App in Azure Active Directory:

As a first step, you need to register an App in Azure Active Directory (i.e., oAuth) by following below steps

  • Connect to the Azure Active Directory (AD) Portal with your Office 365 credentials.
  • Register a new Dynamics 365 App by following steps mentioned here
  • Once you are done with App registration, copy ‘Application ID’ and ‘Home page’ values, which you need to use next steps.

PostMan_14

Setup your Postman tool:

Create ‘Environment’

  • Create a new Postman ‘Environment’ with below variables. This is one time activity for a single D365 instance.
    • url : Your Dynamics 365 URL
    • clientid : ‘Application ID’ from Azure AD,  generated in above section.
    • version : Dynamics version
    • webapiurl : Set this to {{url}}/api/data/v{{version}}/
    • callback : ‘Home page’ value from Azure AD,  generated in above section.
    • authurl : Set this to https://login.microsoftonline.com/common/oauth2/authorize?resource={{url}}
  • I created a new ‘Environment’ with name ‘DynamicsCRM’ and it looks as below

PostMan_13

Generate oAuth Access Token:

Post ‘Environment’ creation, we need to generate oAuth Access Token. This is one time activity for a single D365 instance.

  • Make sure you select ‘Environment’ created in previous section. In my case its ‘DynamicsCRM’.
  • Under ‘Authorization’ tab, set ‘Type’ to ‘oAuth 2.0’ and click on ‘Get New Access Token’.

PostMan_15

  • In the ‘GET NEW ACCESS TOKEN SCREEN’ make sure you set values as below.

PostMan_1

  • Click ‘Request Token’ and system will prompt you for credentials, pass your O365 credentials.

PostMan_2

  • When you click ‘Next’, you may encounter “response_type ‘token’ is not enabled for the application” exception.
    • To fix this, make sure in your Azure AD Application’s manifest “oauth2AllowImplicitFlow” property is set to ‘true’

PostMan_4

  • You may also encounter “The reply url specified in the request does not match the reply urls configured for the application“.
    • To fix this, make sure you set the Postman’s ‘Environment’ -> ‘callback’ variable set correctly.
  • Click ‘Continue’ to complete the ‘Access Token’ generation process.
  • On successful ‘Access Token’ generation, you would get the screen as below.

PostMan_8

  • Click ‘Use Token’.

That’s it! we are done with settings and its time to test the Dynamics API’s with Postman

Test by executing ‘WhoAmI’ request:

  • Make sure you select the right ‘Environment’ and generated your ‘Access Token’.
  • Select ‘GET’ operation and set the URL as {{webapiurl}}WhoAmI
  • Click ‘Send’
  • You should get “200 OK” response up on success.

PostMan_10

  • You may get “401 Unauthorized” response.

PostMan_11

  • To fix this, make sure you set “Add authorization data to” to “Request Headers”.

PostMan_12

🙂

 

Advertisements

Dynamics 365 – Configure Custom ‘Help Page’

February 4, 2019 Leave a comment

‘Help’ feature in Dynamics 365 is a useful and an intuitive way to provide guidance to the end users.

Sometimes we may get a requirement from customer to configure ‘Custom Help’ page.

Its simple to configure the custom help screen from Dynamics 365 ‘Admin Center’ Settings screen.

Steps to configure custom Help URL:

  • Connect to your Office 365 Admin Center
  • In the ‘Environments’ tab, select the instance  and click on ‘Settings’

HelpPage_1

  • In the ‘Settings’ screen, click on ‘Products -> Features’

HelpPage_5

  • Under ‘Help features’, turn ON the “Custom help for customizable entities”.
  • In the ‘Global custom help URL’, provide your custom web link.
    • I provided my blog URL in this case.
  • Select ‘Append parameters to URL’ option, if you want to pass the “typename”, “formid” etc.. parameters to your custom URL.

HelpPage_2

  • Alternatively, you can also configure the same from ‘Administration -> System Settings’

HelpPage_6

Steps to test the Help URL:

  • Connect to your dynamics instance.
  • Click on Help(?) icon

HelpPage_3

  • You will be redirected to the configured URL

HelpPage_4

🙂

Dynamics 365 – Get ‘April 2019’ update

February 4, 2019 Leave a comment

Last weekend, I subscribed to a Dynamics 365 30 days trail and noticed that now we can upgrade to ‘April 2019’ update and start exploring the features.

Below are the steps to update your instance to ‘April 2019’.

  • Connect to your Office 365 Admin Center
  • In the ‘Environments’ tab, select your environment and navigate to ‘Settings’ page by clicking on Instance name hyperlink.

Apr2019_3

  • In the ‘Settings’ screen, under the ‘Updates’ tab, click on ‘Manage’ link

Apr2019_2

  • In the ‘Updates’ slider window, click on ‘Active now’ to get the ‘April 2019’ update

Apr2019_1

  • Confirm by providing your instance name in the text box, as below.

Apr2019_4

  • That’s all we need and enjoy your ‘April 2019’ update.

Apr2019_5

Note:

  • You cannot revert once you activate the ‘April 2019’ update.

Refer the link for what’s included in ‘April 2019’ update

🙂

Dynamics – Troubleshooting Server Side Sync exceptions

January 22, 2019 Leave a comment

Server-side synchronization is used to synchronize your email system with Dynamics 365 for Customer Engagement apps at the server level.

Now coming to the issue, I was configuring Server side sync on my CRM on-premise instance with ‘Gmail’ as host and got the below error while testing the mail delivery of a ‘Mailbox’ using ‘Test & Enable Mailbox’ option.

ss_1

Reason:

  • In my case, its CRM on-premise installation and were having below 3 servers
    • Front End Server – Contain CRM WebApp
    • Application Server – Contain Services (Async, Sandbox, etc..)
    • Back End Server – Contain SQL Server and SSRS
  • Issue was ‘Incoming Port’ and ‘Outgoing Port’ were not opened on my ‘Application server’ which caused the issue

Now lets see few sanity steps and how to troubleshoot issues.

[Sanity Step] Make sure Ports and Mailbox settings are correct:

  • Test the settings provided in ‘Email Server Profile’ using console application

ss_3

  • Create a simple C# console application with below code and pass the settings (i.e., Port, host names etc) mentioned in ‘Email Server Profile’

using (MailMessage mail = new MailMessage()){
int portNumber = Convert.ToInt32(ConfigurationManager.AppSettings[“port”].ToString());
var smtpAddress = ConfigurationManager.AppSettings[“smtpAddress”].ToString();
var emailFromAddress = ConfigurationManager.AppSettings[“emailFromAddress”].ToString();
var password = ConfigurationManager.AppSettings[“password”].ToString();
var emailToAddress = ConfigurationManager.AppSettings[“emailToAddress”].ToString();

mail.From = new MailAddress(emailFromAddress);
mail.To.Add(emailToAddress);
mail.Subject = “Set mail subject”;
mail.Body = “Set mail body”;
mail.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)){
smtp.Credentials = new NetworkCredential(emailFromAddress, password);
smtp.EnableSsl = enableSSL;
Console.WriteLine(“Sending mail…”);
smtp.Send(mail);
Console.WriteLine(“Mail has been sent…”);
}
}

App Settings:

<appSettings>
<add key=”port” value=”587″/>
<add key=”smtpAddress” value=”smtp.gmail.com”/>
<add key=”emailFromAddress” value=”rajeevpentyala@gmail.com”/>
<add key=”password” value=”*******”/>
<add key=”emailToAddress” value=”rajeevpentyala@live.com”/>
</appSettings>

[Sanity Step] Make sure your Incoming and Outgoing server locations are reachable:

  • From command prompt, ping the locations with below command and make sure you are getting response
    • Ping -t {location}   (Ex- Ping -t smtp.gmail.com)

ss_4

[Issue] If failed with “The SMTP server requires a secure connection” exception

  • Connect to your Gmail account. Link
  • Turn on the “Less secure app access” option
ss_5

Turn on ‘Less secure app access’

Refer this article for more exhaustive list of troubleshooting options

🙂

[Logic App and HTTP Request Trigger] Create a record in D365

December 20, 2018 Leave a comment

We got an ask from client that they should be able to Insert contacts in D365 from their Java application and requested our help.

To fulfill the ask, one option would be configuring S2S authentication so that Java application can connect to D365 using ADAL library and insert contacts.

Another option is using “Logic App” with “Http Request Trigger”.

High level approach:

  • Create a Logic App with ‘When a HTTP request is received’ trigger
  • Pass Contact record information in Json format as Request
    • Use ObjGen site to generate desired Json data.
    • This site seamlessly generates Json data based on our input. As I am going to create a Contact record, I generated below JSon data.

LogicApp_3

  • From Logic App, read the Json data and create Contact record using D365 connector
  • Finally capture the created Contact GUID in ‘Response’

Lets see the step by step approach to create Logic App and test.

Pre-requisites:

  • Dynamics 365 instance. Subscribe for trail if you have’t already
  • Azure Subscription.Subscribe for trail if you have’t already

Once you got the D365 and Azure Portal subscriptions below are the steps to create LogicApp.

Create a Logic App:

  • Connect to your Azure Portal and create a new ‘Logic Apps’. Refer article for steps to create Logic App.
  • From the list select ‘When a HTTP request is received’ trigger

LogicApp_4

  • In the next screen, click on “Use sample payload to generate schema” to generate the Json schema.

LogicApp_5

  • Paste the Json format prepared in ObjGen site

LogicApp_6

  • Click on ‘Done’ so that LogicApp generates “Request Body jSON Schema”

LogicApp_7

  • Next, we need to connect to D365 to save the Contact

LogicApp_8

  • Click ‘New Step’ and select ‘Dynamics 365’ connector. From the ‘Actions’ select ‘Create a new record’ and provide credentials and connect to your Instance

LogicApp_9

  • From the ‘Entity Name’, select ‘Contacts’
  • Map the Contact entity fields with the fields from ‘Dynamic content’ popup.
    • As ‘Company Name’ is a Look up to ‘Account’ entity, make sure you map
      • ‘Company Name Type’ = ‘accounts’
      • ‘Company Name’ = ‘id’ passed from Json

LogicApp_10

  • Next we need to capture the ‘Response’, choose ‘Response’ from ‘Actions’

LogicApp_11

  • In the ‘Response’ control,
    • In the ‘Headers’, add ‘Content-Type’ as key and ‘application/json’ as Value.
    • In the ‘Body’, form your output string and ‘Contact’ field from ‘Dynamic Content’ to capture the GUID

LogicApp_12

  • Save the Logic App

Test the Logic App:

  • Copy the “HTTP POST URL” from the “When a HTTP request is received” control.

LogicApp_13

Using Post Man:

  • Create a ‘POST’ request and paste the URL copied from Logic APP
  • In the ‘Headers’, add ‘Content-Type’ as key and ‘application/json’ as Value.

LogicApp_14

  • In the ‘Body’, paste the Json (You can copy the Json format prepared in ObjGen site)
  • Click ‘Send’ to call Logic App and capture the Response.

LogicApp_2

Using jScript and HTML:

  •  Below the jScript to call the Logic APP URL by passing JSon and capture the response

<html lang=”en” xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta charset=”utf-8″ />
<title>Test Logic App</title>

function TestLogicApp() {
try {
var xhr = new XMLHttpRequest();
var url = “Logic App URL“;
xhr.open(“POST”, url, true);
xhr.setRequestHeader(“Content-Type”, “application/json”);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
alert(xhr.responseText);
}
};
var data = JSON.stringify({
“firstname”: “Rajeev”,
“lastname”: “Pentyala”,
“Account”: {
“id”: “A16B3F4B-1BE7-E611-8101-E0071B6AF231”,
“Name”: “A Datum Corporation”
}
});
xhr.send(data);
} catch (e) {
alert(“Error – ” + e.description);
}
}

</head>
<body>
<input type=”button” value=”Post” onclick=”TestLogicApp()” />
</body>
</html>

  • Open the HTML page and click the ‘Post’ button to capture the Response returned from LogicApp

LogicApp_1

Troubleshoot and track the history:

  • To troubleshoot and track the Requests, from the ‘Logic App’, click on ‘Overview’ and check under ‘Run history’

LogicApp_15

🙂

[D365 CE] Migrate data to field with “Time Zone” format

December 14, 2018 Leave a comment

Have you ever worked with “Decimal” field with “Time Zone” Format?

Lets assume your Dynamics application has a global presence and you need to capture “Customer” info along with their “Time Zone”, we can create a Decimal field with “Format” set as “Time Zone”.

TZ_2

With “Time Zone” format, even though, you create a field of “Decimal” type, in UI it will render as drop down and in ‘Advanced Find’ you get a string.

TZ_3

Lets see how to migrate data to the “Time Zone” format field.

Whats “Time Zone” format:

As you would have noticed in above screens, “Decimal” field rendered as Drop down with all time zone options. Now the question is where we are getting these option?

The answer is, Dynamics has an internal entity named “Timezonedefinition” which pulls the time zone options from.

“Timezonedefinition” entity will have below 2 fields

  • Standardname – Name of the Time Zone
  • Timezonecode – Time zone code which is a decimal value

When you add a ‘Decimal’ field with ‘Time Zone’ format to an entity, in UI (i.e., Forms, Advanced Find, Views, etc.) you would get the ‘Standardname’ (i.e., Time zone name) however in the back end ‘Timezonecode’ gets saved.

TZ_4

To check that, export the records to Excel and you would find decimal values in “Timezone” field.

TZ_5

As you notice above, “(GMT-10:00) Hawaii” field rendered as 2 in exported excel, which “Timezonecode”

How to migrate data to “Time Zone” format field:

  • First you need to fetch the “Time zone codes” using “RetrieveMultiple” SDK call (Sample code below)

var request = new RetrieveMultipleRequest{
Query = new QueryExpression(“timezonedefinition”){
ColumnSet = new ColumnSet(“timezonecode”, “standardname”),
}
};

var response = (RetrieveMultipleResponse)_service.Execute(request);

foreach (var item in response.EntityCollection.Entities){
var timeZone = (Entity)item;Console.WriteLine(String.Concat(“Time zone name: “, timeZone[“standardname“], “, time zone code: “, timeZone[“timezonecode“]));
}

  • Executing above code would fetch “Timezone Names” along with “Timezonecode”

TZ_1

  • Once you have the codes, you can migrate the records by setting the “Time zone codes” to “Time zone format” field.
  • In the excel file, add new records with “Timezonecode”

TZ_7

  • After the successful excel import you should see new records in UI with “Time Zone Name” replaced with “Time zone code” passed from excel.

TZ_6.PNG

🙂

 

 

[D365 CE Online] Debug Async Plug-in using “Persist to Entity” profiler option

December 1, 2018 4 comments

As you are aware, using Plug-in Profiler option we can debug D365 online plug-ins by throwing exception and capturing the Serilaized profile. Refer my previous article

With the ‘Exception’ profiling option, you first need to trigger the event and capture the exception log. For example, if you need to debug “Post Account Create” plug-in, you first need to trigger the event (i.e., Create Account from D365 application) and capture the exception log. This ‘Exception’ option would be apt, if your plug-in registered in Sync mode.

What if your plug-in is Async? Answer is, using “Persist to Entity” profiler option.

Plugin Profile 1

Let’s see how to debug Async Plug-in step by step.

Configuring Profiler in Plugin Registration Tool:

  • Connect to your Dynamics instance using Plug-in registration tool.
  • Click on ‘Install Profiler’ button
  • Register a new plug-in assembly and add an Async step
    • In this article, I registered an Async step on Post Account Creation

Plugin Profile 9

  • Select the Plug-in step and click on ‘Start Profiling’
  • In the “Profiler Settings” screen, choose “Persist to Entity” option and click “OK”

Plugin Profile 1

Trigger Account Creation from D365 Application:

  • Connect to D365 application and create a new Account

Plugin Profile 8

  • As we opted for “Persist to Entity” profiler option, an entry will get created in “Settings -> Plug-in  Profiles” entity.
  • Go to “Settings -> Plug-in  Profiles”, open the newly created “Plug-in  Profile” record (Note: Async plug-in takes time to create a new “Plug-in Profile” record).

Plugin Profile 2

  • In the “Plug-in Profile” record, you would notice the Serialized content in “Serialized Profile” field. This is same as what you get in Exception download log if you would have opted for “Exception” profile setting.

Plugin Profile 3

Debug the Plug-in:

Once an entry got created in “Plug-in Profile” record

  • Open the Plug-in class file in Visual Studio and attach “Plug-in Registration Tool” process

Plugin Profile 5

  • Add a break point in your Plug-in class file to debug.
  • Open the “Plugin Registration Tool”
  • Select the Plug-in step and click on “Debug/REPLAY PLUG-IN EXECUTION” button
  • In the “Replay Plug-in Execution” screen, set
    • Profile = Click on ‘Down Arrow’ button to pick your “Plug-in Profile” record from D365 (Refer screen)
    • Assembly Location = Plug-in dll
    • Plugin = Class Name

Plugin Profile 10

  • Click on “Start Execution”

Plugin Profile 11

  • You should see a break point hit in Visual Studio.

Plugin Profile 7

  • Press F10 to proceed with debugging.

🙂