Month: March 2018

Work with Alternate Keys

Concept of Alternate Keys has been introduced with Microsoft Dynamics CRM Version 2016.

All Microsoft Dynamics CRM records have unique identifiers defined as GUIDs. These are the primary key for each entity. However if you have alot integrated systems in your organization – it would be very difficult for other systems to retrieve or update records using the guids as they wont necessarily store CRM’s internal GUIDs. Hence you can create an alternate key which is actually a data in other systems – they can easily update or retrieve data from CRM using this.

Only below field types can be added as an alternate key :

  1. Decimal Number
  2. Whole Number
  3. Single Line of Text

Point to note is that for a single entity, only 5 alternate keys are allowed in CRM.

Apart from Above , Alternate keys will stop creating duplicate records in the system, be it normal creation , excel import , or from external service.Wow how cool is that!

To Create an alternate key , go to customization > Entity> Expand the entity and look for “Alternate Keys” option > click on New and give display name and schema name > select the field for which you want to enable it > click on the right arrow > click on Save.

when you save an alternate key it, you are actually creating an async job which goes through following status :

  • Pending
  • In Progress
  • Active
  • Failed

alternatekey

Once status shows “Active” it means its ready to be used:

alternatekey1

you can very well use alternate keys with WebApi , take reference from the below :

https://community.dynamics.com/crm/b/dutchcrmandsharepoint/archive/2016/12/06/using-alternate-keys-with-the-webapi

Write to me if you have any questions on this topic.

I hope this helps!

Cheers!

Know if an email has been replied or worked upon

This is very common question that i get on community or on other forums on how to identify if an email has been replied or worked upon by a user.

Well the easiest approach to tackle this is that there is a field on emails as parentactivityid  which can be used and put on the views, this field basically will contain the email on which you have replied.

So if this field contains data, it means someone has replied on this email.

for example , see below :

Capture

  1. My first email doesn’t contain anything in the parentactivityid because its a fresh sent email.
  2. My second is actually the email which i have sent above – it has the parent activity id as the first email.
  3. My third email is a reply on the previous email received, hence it has that in the parentactivity id column.
  4. My last email is the received email which has the parentactivity id as the email which i sent previously.

Hence, the logic should be like.

1.)

Email direction = incoming

parentactivityid = contains email

Action = you have to reply to this email.

2.)

Email direction = outgoing

parentactivityid = contains email 

Action = it means it has been replied.

3.)

Email direction = incoming

parentactivityid = doesn't not contains emails

Action = you have to work on it

4.)

Email direction = outbound 

parentactivityid = doesn't not contain email

Action = its a fresh email.

I hope it makes sense.

Cheers!

How to Setup Microsoft Dynamics CRM Portal

In this blog i am going to show you how you can setup Microsoft dynamics CRM Portal trial for your learning or business purpose.

  1. Login to dynamics CRM> click on main navigation and click on “Administration” button(it shows in my local language in the screenshot but you can look for that symbol):
    1.jpg
  2. Once you are navigated to Admin Center click on the main Navigation again and scroll down to “Admin Centers” , look for ” Dynamics 365″.
    2.jpg
  3. you will be presented with the screen like below, click on Applications tab:
    3
  4. Now, Click on “Portal Add-On” and then click on “Manage” Button:
    4.jpg
  5. you will be presented with Main portal setup page, Enter the desired name and select the URL you want ( make sure its unique):
    5
  6. Scroll down more and enter details like the admin , portal type and portal audience. Once you okay with the details entered click on Submit:
    6.jpg
  7. Once you click on submit you will be presented with Agreement page , click on Accept.
  8. Post this it will show you the below page – which means you portal setup has started:
    7.PNG
  9. Wait for 5 mins and login back to dynamics crm , you should now see a new module added as “Portal”:
    8.png
  10. You can now login to your portal using the URL which we create on the step 5:
    9

 

I hope this helps. I will be writing few more blogs on how you can get started with Customizing your portal as per business needs so stay tune.

 

Cheers!

 

———- is not a valid status code for state code entity

Often you see this error in your plugin or Webapi actions when you trying to play with the status and status reasons in microsoft dyamics crm.

so, lets understand this.

Suppose i have below status and status reasons:

status

as you can see there is a set of status reason you can only combine with and “Active” Statecode and some with “Inactive” statecode.

So ,if you have a status reason which belongs to an active statecode but you use it with an inactive statecode and vice versa, you will be presented with this error.

and in the error first line you can actually see what optionset value it is talking about.

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!