Tag Archives: 2011

Call Centre Optimised CRM–An Example Solution

CRM in the Call Centre is a different beast from regular CRM with factors such as telephony integration and click minimisation playing a big influence.  In this post I will present an example approach to optimising the Call Centre Agent experience in a Customer Service environment.  Every customer scenario is different so this is not meant to be an all encompassing solution, rather its just an example of how we can streamline the user experience with Microsoft CRM 2011.

In this scenario the CTI is going to always pop the Phone Call form.  If the CTI can match the caller the Phone Call will be pre-populated with the CRM Contact.  Otherwise a dummy “Unknown Caller” Contact will be populated.  The Phone Call will be created by custom code and then launched to the user as a saved record.  

Here’s my phone call screen, as the Call Centre Agent would receive when the CTI has successfully matched to a Contact:

image

And when not matched:

image

When the caller has been matched to an existing Contact in CRM their Case History is displayed on the form (with the help of an HTML web resource):

image

The Call Centre Agent greets the caller and determines their identity and the reason for their call.  Here’s what can happen:

Use Case 1:

If the caller has been correctly matched by the CTI and they are calling in regards to an existing Case the Agent will click the Existing Case button on the Ribbon:

image

This pops a Case lookup window displaying the Cases related to the Caller:

image

The Agent selects the relevant Case, and the lookup window closes, as does the Phone Call form and then the Case form pops for the user:

image 

Also note the Caller’s phone number and email address are populated directly onto the Case record for ease of access.

The user can then progress the Case with the Customer (add Notes, check the status of open activities, resolve the Case, etc.).

Behind the scenes the Phone Call has been linked to the Case (so that it appears under the Case’s History) and it has been auto-completed.   

This scenario has been completed in 2 clicks.  That’s pretty good!

Use Case 2:

If the caller was not matched by the CTI and they are legitimately a first time caller who is not yet in CRM the Agent will click the New Case button on the Ribbon:

image

Immediately the Phone Call form closes and a Case form is popped:

image

Now if we cater for anonymous callers then this Case can be progressed just like any other case.  It is already attached to our “Unknown Caller” Contact.

Otherwise, you will notice the Case form has a Quick Create New Contact section on the form (a customisation I have blogged about previously).  The Agent can easily populate this section…

image

… and the Contact will be created and the Case re-associated accordingly:

image

Again, behind the scenes the Phone Call has been linked to the Case and has been auto-completed.

This solution also supports the following use cases:

– The caller is not auto-matched by the CTI as they have called from a different number.  The Agent can simply use the Contact lookup field on the Phone Call form to locate their Contact record.   The process flow then continues as if they were matched by the CTI.

– The caller is matched by the CTI but they are calling in regards to a new issue.  This scenario starts of like Use Case 1 but the user would click the New Case button, and then the scenario follows Use Case 2.

What I like about the solution is:

  • Simplicity for the user – the Phone Call pops, they click either the New Case button or the Existing Case button
  • Processing speed – this solution has the minimal number of clicks possible and does not require the use of the Contact form at any stage
  • Consistent process for emails – this same design could be applied to the Email form for handling inbound customer service emails
  • Automatic activity history – every inbound call results in a (saved) Phone Call activity without any risk of the user not creating/saving the record.  And the Phone Calls are auto-completed for the user.
  • Distinct Cases for each unique Service Request – we are not creating a Case for every call, only when the Agent identifies the call relates to a new issue.
    Hopefully this gives you an idea of what Microsoft CRM is capable of.  Out of the box Microsoft CRM like any CRM system can be a little clunky but the power of Microsoft CRM is its rich (and upgrade friendly!) extensibility.  Don’t be scared of this sort of customisation, Microsoft have designed Microsoft CRM expecting us to configure this types of solutions, and it is more configuration then it is customisation.  After all, I was able to build this out and I’ve never compiled a piece of code in my life.
    If you are not seeing the sort of rich user experience I have described here in your CRM system, well, it’s probably time you found yourself a decent CRM vendor. Smile
      This example solution is available for download here
      To deploy, import the Solution and publish.  Then edit the Configuration entity definition so that it appears in the Settings area (this is meant to appear but didn’t for me when I tested this), create a Contact called “Unknown Caller” and create a Configuration record like the below:

    image

     

    The “Value” you need is the GUID of the Active Contacts view which you can get by opening that view to customise it and then selecting Copy Link from the Actions menu.

     

    Technical Notes

    For those that are curious here’s how I’ve achieved the above.  It’s all real apart from the Case History view which I didn’t bother to build out.

    Phone Call Java Script

    • Change the lookup view of the Sender field to search against Contacts rather than Accounts by default
    • Custom “Existing Case” lookup field added
    • The 2 ribbon buttons were added
    • The “Existing Case” button pops the lookup view of the “Existing Case” lookup field (by firing it’s Click event)
    • Once the “Existing Case” field is populated it is replicated into the “Regarding” field.  Then the SaveAsCompleted function behind the Mark Complete ribbon button is fired.  Then the Case form is launched for the Case GUID specified in the “Existing Case” field.
    • The “New Case” button calls the CRM REST service and creates a new Case record for the Contact specified in the Sender field.  It then populates this Case GUID into the “Regarding” field, fires the SaveAsCompleted function and then launches the Case form.

    Case Java Script

    • Change the lookup view of the Customer field to search against Contacts rather than Accounts by default
    • Hide the Quick Create section unless the Customer field is blank or “Unknown Contact”
    • Once all Quick Create fields are populated the CRM REST service is called to create the new Contact and then that new Contact is populated into the Customer field and the Quick Create section is then hidden
    • Whenever the Customer field changes the CRM REST service is called to retrieve the Contact’s Email Address and Phone Number and these are then populated onto the CRM form

    I have provided sample code for these components in my previous posts. 

    Working With REST Results in CRM 2011

    A short post today.   When using Microsoft CRM 2011’s REST oData End Point to create a new record or to retrieve an existing record the result is provided to you in 2 different ways.  This can catch you out.

    Retrieving Records

    When querying for existing records the result provided by the oData query is an array of CRM records.  You can access that by referring to data.d.results[0] as illustrated below:

    success: function (data, textStatus, XmlHttpRequest) {
    	var Contact = data.d.results[0];
    	if (Contact.Telephone1 != null) {
    		Xrm.Page.data.entity.attributes.get("new_phonenumber2").setValue(Contact.Telephone1);
    		alert("phone set");
    	}
    

    I’m placing the first CRM object in that array into a variable called Contact.  In the above example my query (which I haven’t included) was performing a top1 selection so I am only expecting one record and therefore only interested in the first record (array value 0). 

    I then retrieve the Contact’s phone number by referring to Contact.Telephone1 where Contact is my object variable and Telephone1 is one of it’s attributes.  To know the attribute name and the correct case to use make sure you test your REST query in IE or using the oData Query Designer.

    Creating Records

    When creating a new record you will be returned the object that was created.  This will be just a single CRM object rather than an array of objects.  You can access that by referring to data.[“d”] as illustrated below:

    success: function (data, textStatus, XmlHttpRequest) {
    	var NewCRMRecordCreated = data["d"];
    	alert(NewCRMRecordCreated.IncidentId);
    

    Hope this helps.  Smile

    Adding a new Button Group to the CRM Ribbon

    Here’s a quick run through on how to add a new Group of buttons to the ribbon in Microsoft CRM 2011.

    Here’s the end result that will be achieved:

    image

    In this scenario we are customising the Phone Call entity’s Form ribbon.  In particular the Main Tab of that ribbon (the tab that carries the name of the Entity).

    To implement this change we need to customise the Phone Call entity.  At present CRM does not provide a UI for Ribbon customisations but the customisation XML does support these changes.  So we need the Phone Call entity’s customization xml.   Create a Solution, add the Phone Call entity, export the solution, unzip and then open the customization.xml file in Visual Studio.

    Collapse the EntityInfo and FormXml nodes and you should see the RibbonDiffXml node, this is where we specify changes to the Ribbon.  Replace the CustomActions line with the following XML:

    <CustomActions> 
      <CustomAction Id="Mscrm.Form.phonecall.CustomGroup.CustomAction" 
                    Location="Mscrm.Form.phonecall.MainTab.Groups._children" 
                    Sequence="110"> 
        <CommandUIDefinition> 
          <Group Id="Mscrm.Form.phonecall.CustomGroup.Group" 
                  Command="Mscrm.Form.phonecall.CustomGroup.Command" 
                  Title="Gareths Group" 
                  Sequence="51" 
                  Template="Mscrm.Templates.Flexible2"> 
            <Controls Id="Mscrm.Form.phonecall.CustomGroup.Controls"> 
              <Button Id="Mscrm.Form.phonecall.CustomGroup.Button.A" 
                      Command="Mscrm.Form.phonecall.CustomGroup.Button.A.Command" 
                      Sequence="10" 
                      LabelText="Button 1" 
                      ToolTipTitle="TipTitle" 
                      ToolTipDescription="TipDescription" 
                      TemplateAlias="o1" 
                      Image16by16="/_imgs/ribbon/newchart16.png"  
                      Image32by32="/_imgs/ribbon/newchart32.png"  /> 
              <Button Id="Mscrm.Form.phonecall.CustomGroup.Button.B" 
                      Command="Mscrm.Form.phonecall.CustomGroup.Button.B.Command" 
                      Sequence="20" 
                      LabelText="Button 2" 
                      ToolTipTitle="TipTitle" 
                      ToolTipDescription="TipDescription" 
                      TemplateAlias="o1" 
                      Image16by16="/_imgs/ribbon/CustomEntity_16.png"  
                      Image32by32="/_imgs/ribbon/CustomEntity_32.png"   /> 
            </Controls> 
          </Group> 
        </CommandUIDefinition> 
      </CustomAction> 
      <CustomAction Id="Mscrm.Form.phonecall.CustomGroup.MaxSize.CustomAction" 
                    Location="Mscrm.Form.phonecall.MainTab.Scaling._children" 
                    Sequence="120"> 
        <CommandUIDefinition> 
          <MaxSize  Id="Mscrm.Form.phonecall.CustomGroup.MaxSize" 
                    GroupId="Mscrm.Form.phonecall.CustomGroup.Group" 
                    Sequence="21" 
                    Size="LargeLarge" /> 
        </CommandUIDefinition> 
      </CustomAction> 
      <CustomAction Id="Mscrm.Form.phonecall.CustomGroup.Popup.CustomAction" 
                    Location="Mscrm.Form.phonecall.MainTab.Scaling._children" 
                    Sequence="140"> 
        <CommandUIDefinition> 
          <Scale    Id="Mscrm.Form.phonecall.CustomGroup.Popup.1" 
                    GroupId="Mscrm.Form.phonecall.CustomGroup.Group" 
                    Sequence="85" 
                    Size="Popup" /> 
        </CommandUIDefinition> 
      </CustomAction> 
    </CustomActions>
    

    We are adding 3 Custom Actions here: 

    • The first Custom Action adds the new Group and the 2 Buttons inside that Group.
    • The second Custom Action adds the MaxSize definition for the Group to the Scaling definition of the Ribbon.  This tells CRM how to display the buttons when the screen size does not require any collapsing of the buttons.
    • The third Custom Action adds the Scale definition for the Group to the Scaling definition of the Ribbon. This tells CRM how to display the buttons when the screen size is insufficient.

    To adjust my sample code for your scenario do the following:

    Do a Find and Replace on “phonecall”, replacing with the name of your entity.

    Change the Location value on line 3 to the relevant Group ID of your entity’s Ribbon definition.  I’ll explain.  In my scenario I wanted to add a Button Group to the Phone Call form’s Main tab so I went and found the Phone Call ribbon definition in the SDK here:

      \sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml\phonecallribbon.xml

    [UPDATE: 14 Dec 2011 – The latest SDK did not include the ribbon definition XML files forcing you to build and run an app from source code provided in order to generate them for your self. I provide instructions on this process here]

    And looked for my Tab in that file, finding it here (see the yellow highlight below):

    image

    I wanted to add a new Group under the Groups section of the Ribbon so the Location value in our customization file needs to be that Groups Id (highlighted in green above) – appended with ._children.  i.e.:

    image

    That’s all you need to change at this stage.  We’ll come back and personalise other settings in a sec, let’s just try and get the button group to appear first.

    Ok, now we need to add some commands to our customization file.  Replace the CommandDefinitions line with the following XML:

    <CommandDefinitions> 
      <CommandDefinition Id="Mscrm.Form.phonecall.CustomGroup.Button.A.Command"> 
        <EnableRules /> 
        <DisplayRules /> 
        <Actions> 
          <Url Address="http://www.google.com" /> 
        </Actions> 
      </CommandDefinition> 
      <CommandDefinition Id="Mscrm.Form.phonecall.CustomGroup.Button.B.Command"> 
        <EnableRules /> 
        <DisplayRules /> 
        <Actions> 
          <Url Address="http://www.google.com" /> 
        </Actions> 
      </CommandDefinition> 
      <CommandDefinition Id="Mscrm.Form.phonecall.CustomGroup.Command"> 
        <EnableRules> 
          <EnableRule Id="Mscrm.ConvertActivity" /> 
        </EnableRules> 
        <DisplayRules> 
          <DisplayRule Id="Mscrm.ConvertActivity" /> 
        </DisplayRules> 
        <Actions /> 
      </CommandDefinition> 
    </CommandDefinitions>
    

    Here again we have 3 bits, 3 Command Definition’s:

    • The first Command Definition defines what should happen when the first button is clicked.  I just have a hardcoded URL being launched. 
    • The second Command Definition defines the 2nd button’s action.
    • And the third Command Definition defines when the Group of buttons should be enabled and visible.  You can alternatively set these rules per button.  You’ll see I am referring to a rule called “Mscrm.ConvertActivity”.   I got this from the phonecallribbon.xml.  This is the rule used for the Convert to Case button.  I find it’s handy to just steal the rule of another button who’s behaviour you want to mimic.

    To adjust my sample code for your scenario do the following:

    Change the URL being launched by each button or replace s jscript function call like the below:

    image

    And find a Display Rule and Enable Rule in your entity’s ribbon.xml that you can use.  You can’t just use my “Mscrm.ConvertActivity” rule as it may not exist on your entity.

    Ok, that should be enough to get our buttons to appear.  To deploy, zip back up the customization.xml file along with it’s other solution files and then import that solution zip file back into CRM and Publish.  Pop your form and you should now see the new Button group and it’s 2 buttons:

    image 

    To adjust the appearance you can now go back and tweak some of the XML attributes (after which you would re-zip, import and publish).

    To change where the Group appears on the Ribbon change the Sequence value under the Group node:

    image

    Refer back to the entity’s ribbon.xml to see what sequence each existing Group has to figure out what value you need to slot your in between:

    image

    Change the Button Group label and the label of the individual buttons here:

    image

    Change the Button icon here:

    image

    You have 2 approaches for setting the button icons.  You can browse the entity’s ribbon.xml (or any entity’s ribbon.xml for that matter, or even applicationribbon.xml) and steal the path and filename of a button you want to use.   Or, you can upload your own button icons as web resources and then reference the web resource, which is done in this manner:

    Image16by16="$webresource:new_star16x16"  
    Image32by32="$webresource:new_star32x32"
    

    That should be enough to get you going.  Hope this helps someone.

    Smile

    Gareth.

    Editing Ribbon Buttons in CRM 2011

    In my previous posts I provide an introduction to working with the Ribbon in CRM 2011 where I demonstrate how to add and remove buttons.   In this post I will explain how to edit existing buttons.

    Let’s start by framing an example.  On the Phone Call form we have Ribbon buttons for both “Convert to Case” and “Convert to Opportunity”:

    image

    You’ll note the poor Convert to Case button got the short straw and is presented as a small button, whilst the Convert to Opportunity button appears in full and with a text label.    But what if we are implementing CRM for Customer Service?  In that scenario we are unlikely to care about Opportunities and would likely prefer these buttons switched around.   Here’s how we do that…

    As described in my previous posts customising the ribbon involves a bit of initial research and then some manual editing of an exported customization XML file.   For the research component what we need to do is have a look at the ribbon definition for the Phone Call form.  We find that in the SDK here:

    \sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml\phonecallribbon.xml

    [UPDATE: 14 Dec 2011 – The latest SDK did not include the ribbon definition XML files forcing you to build and run an app from source code provided in order to generate them for your self. I provide instructions on this process here]

    Open that file in Visual Studio and locate the XML that represents these buttons we want to change.  In this case we want to find the form ribbon’s Main tab:

    image

    Always make sure you are looking at the right Tab as similarly named button may appear on the SubGrid tab and HomepageGrid tabs as well.

    The lesson for first timers I want to reiterate here is DO NOT change this XML file.  It will have no effect.   This file is essentially documentation of the out-of-the-box CRM ribbons it is no way used by CRM to render the ribbons.   To change the ribbon we need to make entries into an exported customization.xml file that contains the definition of the Entity involved.

    So jump back to CRM, create a Solution called PhoneCall and add the Phone Call entity into that Solution.  Export that Solution, unzip the file and then open customization.xml file in Visual Studio.  Collapse the EntityInfo and FormXml nodes and you should see the RibbonDiffXml node, this is where we specify changes to the Ribbon:

    image

    Replace the CustomActions line with the following XML:

    <CustomActions> 
      <CustomAction Id="GT.switch.button.sequence1" 
                    Location="Mscrm.Form.phonecall.MainTab.Convert.Controls._children" 
                    Sequence="1"> 
        <CommandUIDefinition> 
          <Button Id="Mscrm.Form.phonecall.Convert.Opportunity"  
                  Command="Mscrm.Form.ConvertToOpportunity"  
                  Sequence="21"  
                  Alt="$Resources:MenuItem_ToolTip_ConvertToOpportunity"  
                  LabelText="$Resources:MenuItem_Label_ConvertToOpportunity"  
                  Image16by16="/_imgs/ribbon/ConvertOpportunity_16.png"  
                  Image32by32="/_imgs/ribbon/ConvertOpportunity_32.png"  
                  ToolTipTitle="$Resources:Mscrm_Form_Other_MainTab_Actions_Convert_Opportunity_ToolTipTitle"  
                  ToolTipDescription="$Resources:Mscrm_Form_Other_MainTab_Actions_Convert_Opportunity_ToolTipDescription"  
                  TemplateAlias="o2"  
                  /> 
        </CommandUIDefinition> 
      </CustomAction> 
      <CustomAction Id="GT.switch.button.sequence2" 
                    Location="Mscrm.Form.phonecall.MainTab.Convert.Controls._children" 
                    Sequence="2"> 
        <CommandUIDefinition>           
          <Button Id="Mscrm.Form.phonecall.Convert.Case"  
                  Command="Mscrm.Form.ConvertToCase"  
                  Sequence="9"  
                  Alt="$Resources:MenuItem_ToolTip_ConvertToCase"  
                  LabelText="$Resources:MenuItem_Label_ConvertToCase"  
                  Image16by16="/_imgs/ribbon/ConvertCase_16.png"  
                  Image32by32="/_imgs/ribbon/ConvertCase_32.png"  
                  ToolTipTitle="$Resources:Mscrm_Form_Other_MainTab_Actions_Convert_Case_ToolTipTitle"  
                  ToolTipDescription="$Resources:Mscrm_Form_Other_MainTab_Actions_Convert_Case_ToolTipDescription"  
                  TemplateAlias="o1"  
                  /> 
        </CommandUIDefinition> 
      </CustomAction> 
    </CustomActions>
    

    Here’s a breakdown of the XML…

    This first bit:

    image

    Reads as:  “I want to perform a Custom Action, lets call my action GT.switch.button.sequence1.  I want to change one of the child nodes in the ribbon definition under the node that has the Id: “Mscrm.Form.phonecall.MainTab.Convert.Controls”.

    Then we have:

    image

    Here we are defining a button.   Now what I did here was I copy and pasted the definition of the Convert to Opportunity button from phonecallribbon.xml into this customization.xml file.  I then changed the properties that I wanted changed.  Specifically I changed the Sequence so that this button would be rendered after the Convert to Case button (which has Sequence 20) and I changed the TemplateAlias to o2 so that this button will be rendered as a little button.   I think this is important as this button group has been defined as 1 big + 2 small button group and I don’t want to defy that.   Those are the only 2 items I have changed.  Because the Id I have specified for this button matches an existing button CRM knows to merge my definition with its existing definition and overwrite it’s definition with mine, rather than creating a new button.

    In my XML snippet in addition to the above I have a second Custom Action containing a second button definition where I specify the overrides I want to the Convert to Case button.   Each button definition needs to sit under it’s own Custom Action header, hence this structure.

    That’s it.  To deploy we simply zip back up the customization.xml file along with it’s other solution files and then import that solution zip file back into CRM and Publish.  

    Here’s the end result:

    image

    You can follow this same approach to change buttons icons, button labels, etc.

    Note: to retain both buttons as large buttons simply set TemplateAlias="o1" on each:

    image

    Quick Create Contact from the Phone Call Form

    Here’s a solution I’ve mocked up to speed up call handling times in a particular Call Centre scenario. 

    Here we have Microsoft Dynamics CRM 2011 deployed into a Call Centre where our CSR’s are tasked with processing inbound calls.   The CRM system has been integrated to the telephony system such that when the caller can be matched to a CRM Contact record that Contact record pops for the user.  

    But when the caller can’t be matched we want the CRM Phone Call form to pop for the user instead and we want to give the user a minimal-click solution that allows them to both record the Phone Call and the Contact.   Here’s what I came up with:

    image

    The telephony integration takes care of popping this form and provides us with the phone number of the caller.  It also populates the subject field for us as well.

    If the CSR’s conversation with the caller indicates they should be in CRM (suggesting that the number they have called in from is new/different) then the CSR can use the out-of-the-box Sender field to search for the caller.

    If the caller is new to us though the user can simply complete these steps to quickly create the Contact and link the Phone Call to the new Contact record:

    1. The CSR clicks into the Title field in the Quick Create New Contact section of the form and populates:

    image

    Note: As soon as the CSR populates one of the fields in this section all the fields in the section become mandatory.

    2. The CSR tabs out of the first field and then populates the second, and then the third:

    image

    3. The user tabs out of the Last Name field and custom code (jscript) is triggered. 

    The code detects that all 3 mandatory fields have now been populated.  The jscript collects the field values from the form and then executes a REST call to create a new Contact based on those values.  On success, the code then updates the Sender field to reflect the Contact that was created and then disables the Quick Create fields:

    image

    For the user, the back end processing is invisible.  They simply followed an intuitive process. 

    A little bit of jscript used in an supported (upgrade friendly) manner has allowed us to streamline the process by removing 6 clicks and one form load.   In a Call Centre environment this is gold.  

    Here’s the jscript behind this.  The OnLoad function needs to be attached to the form’s OnLoad event.  The NewContact function needs to be attached to the OnChange event of the Title, First Name and Last Name fields.  The CreateContact function does the heavy lifting.

    // Set lookup value of a field 
    function SetLookupValue(fieldName, id, name, entityType) { 
        if (fieldName != null) { 
            var lookupValue = new Array(); 
            lookupValue[0] = new Object(); 
            lookupValue[0].id = id; 
            lookupValue[0].name = name; 
            lookupValue[0].entityType = entityType; 
            Xrm.Page.getAttribute(fieldName).setValue(lookupValue); 
        } 
    } 
    
    function DisableFields() { 
        Xrm.Page.ui.controls.get("new_title").setDisabled(true); 
        Xrm.Page.ui.controls.get("new_firstname").setDisabled(true); 
        Xrm.Page.ui.controls.get("new_lastname").setDisabled(true); 
        Xrm.Page.ui.controls.get("phonenumber").setDisabled(true); 
    } 
    
    function MakeFieldsMandatory() { 
        Xrm.Page.data.entity.attributes.get("new_title").setRequiredLevel("required"); 
        Xrm.Page.data.entity.attributes.get("new_firstname").setRequiredLevel("required"); 
        Xrm.Page.data.entity.attributes.get("new_lastname").setRequiredLevel("required"); 
        Xrm.Page.data.entity.attributes.get("phonenumber").setRequiredLevel("required"); 
    } 
    
    function MakeFieldsNonMandatory() { 
        Xrm.Page.data.entity.attributes.get("new_title").setRequiredLevel("none"); 
        Xrm.Page.data.entity.attributes.get("new_firstname").setRequiredLevel("none"); 
        Xrm.Page.data.entity.attributes.get("new_lastname").setRequiredLevel("none"); 
        Xrm.Page.data.entity.attributes.get("phonenumber").setRequiredLevel("none"); 
    } 
    
    function OnLoad() { 
        if (Xrm.Page.ui.getFormType() == 1) { 
            Xrm.Page.getAttribute("subject").setValue("Inbound phone call"); 
            Xrm.Page.getAttribute("phonenumber").setValue("+65 9784 5862"); 
        } 
        else if (Xrm.Page.ui.getFormType() != 1) { 
            DisableFields(); 
        } 
    } 
    
    function NewContact() { 
        if (Xrm.Page.getAttribute("new_title").getValue() == null && 
                Xrm.Page.getAttribute("new_firstname").getValue() == null && 
                Xrm.Page.getAttribute("new_lastname").getValue() == null && 
                Xrm.Page.getAttribute("phonenumber").getValue() == null) { 
            MakeFieldsNonMandatory(); 
        } 
        else if (Xrm.Page.getAttribute("new_title").getValue() != null && 
                    Xrm.Page.getAttribute("new_firstname").getValue() != null && 
                    Xrm.Page.getAttribute("new_lastname").getValue() != null && 
                    Xrm.Page.getAttribute("phonenumber").getValue() != null && 
                    Xrm.Page.data.entity.attributes.get("from").getValue() == null) { 
            CreateContact(); 
            DisableFields(); 
        } 
        else { 
            MakeFieldsMandatory(); 
        } 
    } 
    
    function CreateContact() { 
        // Get the CRM URL 
        var serverUrl = Xrm.Page.context.getServerUrl(); 
    
        // Cater for URL differences between on premise and online 
        if (serverUrl.match(/\/$/)) { 
            serverUrl = serverUrl.substring(0, serverUrl.length - 1); 
        } 
    
        // Specify the ODATA end point (this is the same for all CRM 2011 implementations) 
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; 
    
        // Specify the ODATA entity collection 
        var ODATA_EntityCollection = "/ContactSet"; 
    
        // Define an object for the CRM record you want created 
        var CRMObject = new Object(); 
    
        // Define attribute values for the CRM object 
        CRMObject.FirstName = Xrm.Page.getAttribute("new_firstname").getValue(); 
        CRMObject.LastName = Xrm.Page.getAttribute("new_lastname").getValue(); 
        CRMObject.Salutation = Xrm.Page.getAttribute("new_title").getValue(); 
        CRMObject.Telephone1 = Xrm.Page.getAttribute("phonenumber").getValue(); 
    
        //Parse the entity object into JSON 
        var jsonEntity = window.JSON.stringify(CRMObject); 
    
        //Asynchronous AJAX function to Create a CRM record using OData 
        $.ajax({ 
            type: "POST", 
            contentType: "application/json; charset=utf-8", 
            datatype: "json", 
            url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection, 
            data: jsonEntity, 
            beforeSend: function (XMLHttpRequest) { 
                //Specifying this header ensures that the results will be returned as JSON.      
                XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
            }, 
            success: function (data, textStatus, XmlHttpRequest) { 
                //This function will trigger asynchronously if the Retrieve was successful 
                //alert("ajax call successful"); 
                var NewCRMRecordCreated = data["d"]; 
                var FullName = Xrm.Page.getAttribute("new_firstname").getValue() + " " + Xrm.Page.getAttribute("new_lastname").getValue(); 
                SetLookupValue("from", NewCRMRecordCreated.ContactId, FullName, "contact"); 
            }, 
            error: function (XmlHttpRequest, textStatus, errorThrown) { 
                //This function will trigger asynchronously if the Retrieve returned an error 
                alert("ajax call failed"); 
            } 
        }); 
    }
    

    You will need to upload the json and jquery libraries as web resources and reference in the On Load event along with the OnLoad function:

    image

    A CRM solution file containing these web resources and the changes to the Phone Call form are available for download here.

    Smile

    Defaulting a Lookup field via a REST query at Form Load

    Here’s some sample code that demonstrates how to dynamically determine the GUID of a related record and use that to default a lookup field on a CRM form on form load.

    In this example I have a dummy Contact record called “new contact” which I want to default onto the Phone Call form each time a new Phone Call record is created. 

    i.e when I click New Phone Call on the ribbon…

    image

    …. I want to see this:

    image

    note: I have also re-configured the Phone Call entity’s Direction field so that “Incoming” is the default.  The idea being that the user is launching the Phone Call form to record an incoming call from an unknown caller.

    Defaulting in a dummy Contact may some an unusual scenario but it is not uncommon to utilise a dummy record when dealing with anonymous callers or when wanting to defer the collection of contact details until later in the process.   In a Call Centre environment for example you will not achieve desired efficiencies if you except having to manually create new Contact records before being able to create Phone Calls, Cases, Opportunities, etc or before being able to convert Phone Calls to Cases or Opportunities (I expand on this Call Centre scenario in my next post).

    Anyway, here’s how to make this work…

    There are 2 parts to this.  Firstly, we need to find out the GUID of the Contact record that we want to default on to our Phone Call.   You could figure this out manually and then hardcode the GUID but then your code will not be transportable across environments.   Instead in this example I have hardcoded only the name of the contact (we can easily create this Contact in each environment, it’s just data).  My dummy Contact is called “new contact” and I use the REST oData endpoint to locate that record’s GUID by searching on that name (An alternative approach would be to  store the GUID in a configuration entity and then use REST to query for the GUID from there, however the same coding approach applies).   And  then secondly, once we know the GUID it’s a relatively simple matter of doing a SetValue to populate the field on the form.

    Here’s the jscript:

    // Set lookup value of a field 
    function SetLookupValue(fieldName, id, name, entityType) { 
        if (fieldName != null) { 
            var lookupValue = new Array(); 
            lookupValue[0] = new Object(); 
            lookupValue[0].id = id; 
            lookupValue[0].name = name; 
            lookupValue[0].entityType = entityType; 
            Xrm.Page.getAttribute(fieldName).setValue(lookupValue); 
        } 
    } 
    
    function GetDefaultContactGUID() { 
        if (Xrm.Page.ui.getFormType() == 1) { 
            // Get the CRM URL 
            var serverUrl = Xrm.Page.context.getServerUrl(); 
    
            // Cater for URL differences between on premise and online 
            if (serverUrl.match(/\/$/)) { 
                serverUrl = serverUrl.substring(0, serverUrl.length - 1); 
            } 
    
            // Specify the ODATA end point (this is the same for all CRM 2011 implementations) 
            var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; 
    
            // Specify the ODATA entity collection (this needs to be specific to your entity) 
            var ODATA_EntityCollection = "/ContactSet"; 
    
            // Specify the ODATA filter 
            var ODATA_Query = "?$select=ContactId&$filter=FullName%20eq%20\'new%20contact\'&$top=1"; 
    
            // Build the URL 
            var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query; 
    
            //Calls the REST endpoint 
            $.ajax({ 
                type: "GET", 
                contentType: "application/json; charset=utf-8", 
                datatype: "json", 
                url: ODATA_Final_url, 
                beforeSend: function (XMLHttpRequest) { 
                    //Specifying this header ensures that the results will be returned as JSON.      
                    XMLHttpRequest.setRequestHeader("Accept", "application/json"); 
                }, 
                success: function (data, textStatus, XmlHttpRequest) { 
                    //This function will trigger asynchronously if the Retrieve was successful 
                    SetLookupValue("from", data.d.results[0].ContactId, "new contact", "contact"); 
                }, 
                error: function (XmlHttpRequest, textStatus, errorThrown) { 
                    //This function will trigger asynchronously if the Retrieve returned an error 
                    alert("ajax call failed"); 
                } 
            }); 
        } 
    }
    

    The code snippet above contains 2 functions.  The “SetLookupValue” function is used to default the lookup field.  It is called by the 2nd function “GetDefaultContactGUID” which is where the REST query is constructed.

    To deploy the above you need to load it into a jscript web resource and then reference that web resource on the Phone Call form and add a call in the Phone Call’s On Load event to the GetDefaultContactGUID function.   You will also need to upload json and jquery supporting  web resources and make sure they are specified in the order shown below:

    image 

    If you’re not sure what I’m talking about when I mention json and jquery web resources have a read of this earlier post.

    That’s it, the code is well commented so have a read of that to understand the syntax. 

    A solution file containing the above web resources and minor change to the Phone Call entity is available here for download.   Hope this helps someone.

    G.

    Building a Microsoft CRM 2011 VM – A Quick Checklist

    Here’s a simple checklist for those (like me) that only do this infrequently.  The instructions are minimal, as they assume you know how to complete each step:

    p.s. I recently purchased a drive caddy that I can swap my DVD-ROM drive out for and an SSD drive and now run my VMs on the SSD and it is brilliant!


    Provision the Windows/SQL Platform:

    • Get your hands on the install media for Windows Server 2008 R2 64-bit SP1 (or whatever the lastest SP is at the time)
    • Define a new Win2008 64-bit Virtual  Machine (VirtualBox is good for this)
    • Enable a shared folder in the VM configuration so you can easily move files between host and guest
    • I have a quad-core laptop with 8GB ram and I like to give my VM 4GB ram and 2 cpu’s.
    • Complete the Windows 2008 installation and initial configuration
    • Install VM Additions
    • Change the Computer Name to something more user friendly like “CRMServer”
    • Turn off “Internet Explorer Enhanced Security” (via Server Manager)
    • Assign a static IP address to the VM (10.0.0.1 will do)
    • Run dcpromo.exe (type dcpromo at a command prompt) and promote the VM to a Domain Controller
    • Add the Web Server role to the VM
    • Upgrade to the latest version of IE and set Google as your default search provider
    • Install Adobe Reader, Silverlight and Flash
    • Install Microsoft Office (Outlook, Word and Excel)
    • Optionally create AD accounts for the various CRM and SQL Services, or, just use the default domain administrator account or the network service account for everything.
    • Install SQL Server 2008 R2 (or SQL 2012) (including Full Text Search and SSRS, and set SQL Agent to auto start)
    • Test SSRS (http://servername/reportmanager)
    • Create an Organizational Unit in the AD to house  the CRM AD Groups (I tend to create one called “CRM”)
    • Go into Group Policy and set passwords never to expire (screenshot below)
    • Run Windows Update and install all patches

    Install CRM:

    • Install CRM Server
    • Test CRM (http://servername:portnumber)
    • Add sample data
    • Create 5-10 demo users in the AD, add them to the Domain Admin group
    • Add the above users into CRM and assign them the CRM Sys Admin role
    • Install CRM Reporting Extensions (SSRS Data  Connector)
    • Test CRM Reports
    • Install the latest CRM Rollup Packs
    • Configure Outlook to send/receive via a Hotmail account
    • Install the CRM Outlook Client and associated Rollup Pack
    • Test the CRM Outlook Client
    • Optionally install Visual Studio, CRM SDK, CRM Dev Toolkit and 3rd party tools like the View Replicator, Ribbon Editor, oData Query Designer, Metadata Browser, etc.
    • Optionally install and configure SharePoint 2010 and the CRM-SharePoint integration
    • Consider creating a SQL Maintenance Plan to schedule nightly SQLbackups
    • Shutdown the VM and then take a backup copy of it

    Some screenshots:

    Editing Group Policy (from Start\Admin Tools\Group Policy Management):

    image

    image