The ‘Mysterious’ Customer Journey Entity In Dynamics 365 Marketing

In today’s blog I am going to be talking about ‘Customer Journey’ entity in dynamics 365 for marketing app or to be specific the ‘Customer Journey Designer’ which looks like below:

customerjourney1

 

I call it ‘Mysterious’ because whatever happens in the journey ‘stays’ in the customer journey. i.e there is no way or its difficult to get the segment/contents being used in it. I am talking about Marketing Email, Marketing Page, Marketing Form etc. The question you might want to ask is why would I need that information? well, because of may be below:

  1. You might have some validations on the content you can use in the customer journey
  2. You might want to retrieve the data for reporting purpose

If you look into the relationships from customer journey to these entities, you wont find anything hence it gets difficult to retrieve these records or perform operations. In short Dynamics 365 Marketing works a little differently then our typical dynamics 365.

Whatever happens inside a customer journey designer sits in a field on this entity named as “msdyncrm_workflowdefintion“. It stores information about content added in this the journey in JSON format. 

customerjourney2

This is how it looks:
customerjourney3

 

Let’s understand what this JSON means:

  1. Each content is stored in a node called “ActivityTypeId“.
  2. The Id of the content is stored in property “Itemid“.
  3. To identify the type of content such as Marketing page form etc. refer to below table because it uses different names to each type of content:

Dynamics Entity Name Internal Name In Customer Journey
Marketing Page LandingPage
Marketing Form MarketingForm
SurveySurvey
Marketing EmailEmail
Marketing Event Event
Marketing SegmentSegment

If you debug and parse this field data into JSON, looks like something below:

customerjourney4

So when you retrieve/query this field, you have to loop through these JSON nodes and do validation using the Guids of these records like in the below example of Javascript:

 var workflowDefintion= formContext.getAttribute("msdyncrm_workflowdefinition").getValue();
 var workflowDefintionData = JSON.parse(workflowDefintion); //Parse it

                    var nodeLength = workflowDefintionData.length;
                    for (var i = 0; i < workflowDefintionData.length; i++) {
                        var node = workflowDefintionData[i];                        
                        /* Check if node is a Marketing page*/                       
                        if (node.ActivityTypeId === "LandingPage" && (i + 1) === nodeLength) {

// Perform Operations here
}

Same way you can do in the code if needed.

I hope this help!

Cheers!

Advertisement

SQL Connection to CRM Database

Dynamics CRM has very efficient web services using which you can retrieve data such as Organization service Or WebApi. However if you still need to retrieve data from database here is a quick code helper – which i am using in a console application.

//Initiate the connection
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLServerConnection"].ConnectionString))
{
//create a command variable
using (var command = connection.CreateCommand())
{
//add query to your command
command.CommandText = "your SQLquery goes here";

// open the connection first and then execute the query using Execute Reader
connection.Open();
result = command.ExecuteReader();

here is the app.config which i have used , i am using the windows authentication hence you donot need to mention credentials.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="SQLServerConnection" connectionString="Server=.;Database=events.website;Trusted_Connection=True;"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>

By Now you will have your dataset in “result”; here is another piece of code to read the data:

 if (result.HasRows)
{
 while (result.Read())
{
string contactid= result["columnName"].ToString();
string contact = result["columnName"].ToString();
DateTime createdonDate= (DateTime)result["createdon"];
string type = result["columnName"].ToString();
}

}
// close the result
 if (result != null)
result.Close();


 

I hope this helps!

Cheers!

Create Text log file – Simplest way possible

We all need to log errors, information, warnings when writing your console application.

while there are several third party tools/methods available which you use in your solution such as Nlog, Log4net… etc. I would still prefer to create my custom code to generate the log file and capture all details as those tools might work on some machine and on some wont also depends badly on the permissions on the system.

below is simple code that i use :

using System;
using System.IO;

namespace YourNameSpace
{
 public static class ErrorLog
 {

public static void Logger(string ErrorCode, string ErrorMsg)
 {
 try
 {
 string path = Directory.GetCurrentDirectory();
 path = path + "\\Logs\\";

// check if directory exists
 if (!Directory.Exists(path))
 {
 Directory.CreateDirectory(path);
 }
 path = path + DateTime.Today.ToString("dd-MMM-yy") + ".log";
 // check if file exist
 if (!File.Exists(path))
 {
 File.Create(path).Dispose();
 }
 // log the error now
 using (StreamWriter writer = File.AppendText(path))
 {
 string error = "\n" + DateTime.Now.ToString() + ":" + ErrorCode + ":" + ErrorMsg;
 writer.WriteLine(error);
 writer.Flush();
 writer.Close();
 }

}
 catch (Exception ex)
 {
 throw new Exception(ex.Message);
 }
 }
 }
}

add this file to your code and later you can use it in your solution anywhere like below :

 ErrorLog.Logger("Info","yourtexthere");

kindly note that this will generate the logs file on your directory where the code is running in that case in the “BIN” folder. You can tweak the code to put it somewhere else if you need.

logs

Hope this helps!

Cheers!

RIP SDK – Dynamics CRM 365 v9

As per the recent communication from Microsoft, Microsoft Dynamics CRM SDK will not be available on Microsoft downloads. If you are working on Dynamics 365 v9, well you have to download every component which was available in the SDK individually.

Every tool will be available via NuGet Manager.

The name will be : Developer Guide not Dynamics CRM SDK.

For more information, visit the below blog :  https://blogs.msdn.microsoft.com/crm/2017/11/01/whats-new-for-customer-engagement-developer-documentation-in-version-9-0

Here is the step by step information on how to download these tools using powershell :  https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/download-tools-nuget

 

i hope this helps.

Cheers!