Friday, December 15, 2017

MS CRM Email Template with dynamic id in link

You are trying to create a custom email to a group of contacts and want to create a URL with a contactid in the query string to customize what they see when they click on that link.

It turns out that you need to understand two things to make this work.

In the Template Editor when you press Insert/Update there is no option for the contactid.

#1 Generating a contact id


To create a contactid merge field you need to type the following which is case sensitive.

{!contact:contactid;}

Now Save the Template and this text will turn into a working merge field that returns the contact id of the contact the email is being sent to.

{!Contact:Contact;}

#2 Be careful about links in the Email Template Editor


The following two lines will not be processed the same way when the emails are sent.

The following line will be merged properly and the contact's email browser will typically display a link.

https://www.myportal.com/OrderService.aspx?id={!Contact:Contact;}&type=0


This line may surprise you since the email will look fine but the link won't work. 
https://www.myportal.com/OrderService.aspx?id={!Contact:Contact;}&type=0

What you get is the following:




Notice that the text of the link is merged, but the href value is not.


What if you want a nicely formatted link?

Please click here to find out more!

At this point I "believe" your only course of action is to manually modify the XML in the email template body in SQL. I haven't tried that yet, but will post additional information if I do.



Wednesday, October 4, 2017

MS Dynamics CRM Web Resources Basic Starter Page

When creating a Web Resource Page in MS CRM there are some basic parts that I've tend to use in all of my pages. These are all contained in the script block above the body.

User Information:

     UserId = Xrm.Page.context.getUserId();
     UserName = Xrm.Page.context.getUserName();

Query String parameters to drive the page

     QueryStringParameters = Xrm.Page.context.getQueryStringParameters();
     
     QueryStringParm = "None";
   
     if (QueryStringParameters["feature"] != null) {

         QueryStringParm = QueryStringParameters["feature"].toString();             
     }

Entity Id  - when you are running in a Form iframe and the entity has been saved.

     EntityId = window.parent.Xrm.Page.data.entity.getId();
 
     Id = QueryStringParameters["id"].toString();

Trigger for Query

  document.onreadystatechange = function () {

         if (document.readyState == "complete") {

           // Typically call a query to populate the page

         }
     }

Function to Open a CRM Form in a new window

  function OpenCRMForm(entityName, entityId) {

         var windowOptions = {
             openInNewWindow: true
         };

         Xrm.Utility.openEntityForm(entityName, entityId, null, windowOptions);

     }