Tag Archives: Javascript

Updated CRM 2011 SDK version 5.0.3 available

Today the MS CRM Team released an updated CRM 2011 SDK version 5.0.3 which can be downloaded here http://www.microsoft.com/downloads/en/details.aspx?FamilyID=420f0f05-c226-4194-b7e1-f23ceaa83b69

Microsoft Dynamics CRM 2011 SDK Download Contents

 The Microsoft Dynamics CRM 2011 SDK download package includes the following files and folders:

  • Bin Folder – Contains the assemblies needed for development using Microsoft Dynamics CRM 2011.
  • HandsOnLabs – Contains training materials for learning to use Microsoft Dynamics CRM 2011.
  • Resources Folder – Contains development resources such as a style guide, images, data import maps and other templates.
  • SampleCode Folder – Contains sample code to demonstrate how to develop using Microsoft Dynamics CRM 2011.
  • Schemas Folder – Contains the schemas used for validation using Microsoft Dynamics CRM 2011.
  • Solutions Folder – Contains sample solutions for use with Microsoft Dynamics CRM 2011.
  • Tools Folder – Contains the tools needed to register plug-ins and workflows, and to create strongly typed classes.
  • Walkthroughs Folder – Contains the completed solutions that correspond to walkthroughs presented in the SDK documentation.
  • LicenseTerms.docx – The Microsoft software license terms for this SDK.
  • CrmSdk2011.chm – The help file containing SDK documentation.
  • Microsoft_Dynamics_CRM_2011_SDK_Readme.htm – This readme file.
Advertisements

Dynamics CRM 2011 Developer Training Kit

Brief Description


This training kit is for .NET developers to learn the development features of Dynamics CRM and help them build applications using Microsoft Dynamics CRM 2011 and CRM Online.

The training kit includes various resources such as

  • Presentations – Presentation decks in PowerPoint (.pptx) format that you can use to learn the concepts.
  • Videos – Video recordings of the presentation along with demos delivered by expert trainers.
  • Hands-on Labs – Hands-on labs with detailed instructions and source code that will walk you through the various development features.

Download the training kit here: Dynamics CRM 2011 Developer Training Kit

Girish Raja originally posted about the kit release and you can see the blog post here

Default Customer Lookup to Contact in CRM 2011

There has been a slight change in the way you default the Customer Lookup field to Contact in CRM 2011 compared with CRM 4.

Use the following code to set the Customer Lookup to Contact instead of Account and set the default view.


document.getElementById("customerid").setAttribute("defaulttype", "2");
Xrm.Page.getControl("customerid").setDefaultView("a2d479c5-53e3-4c69-addd-802327e67a0d");

The first line sets the default entity type to Contact for the Customer Lookup dialog.

The second line sets the Customer Lookup dialog’s view to the ‘Contacts Lookup View’ using its guid value. If you do not use this line of code it will default to the ‘My Active Contacts View’ or whatever you have selected as the default Contact view.

Accessing the Parent Form Xrm.Page in CRM 2011

For those of you trying to access a parent form’s Xrm.Page object in CRM 2011 you can use the following syntax.

From an IFrame HTML page

document.parentWindow.parent.Xrm.Page

From a new window/dialog

window.top.opener.parent.Xrm.Page

An example of a new window being used is when you are viewing the Account Form and then choose to create a new Contact from the left hand navigation pane and then within the Contact Form you need to access the Account Form (parent).

Potential CRM 4 syntax to be replaced is as follows

window.opener.parent.document.crmForm
window.opener.document.crmForm
window.opener.parent.crmForm

If you have downloaded the CRM 4 to CRM 2011 JavaScript Converter Tool before December 2010 then you can add the following code snippets to the TOP of the ConversionList.xml file straight after the <snippets> node, alternatively just download the tool again.


    <snippet>
      <crm4>window.opener.parent.document.|_|;</crm4>
      <crm5>window.top.opener.parent.|_|;</crm5>
    </snippet>
    <snippet>
      <crm4>window.opener.document.|_|;</crm4>
      <crm5>window.top.opener.parent.|_|;</crm5>
    </snippet>
    <snippet>
      <crm4>window.opener.parent.|_|;</crm4>
      <crm5>window.top.opener.parent.|_|;</crm5>
    </snippet>

Both Mitch Milam MVP and I searched high and low for this solution as the Xrm.Page object is not in the DOM at that same location as the CRM 4 crmForm object. Please let us know if you experience any problems with accessing parent forms and we will try and help you.

Also if you liked my CRM 4 to CRM 2011 JavaScript Converter Tool then you might like to take a look at Mitch Milam’s CRM Migration Assistant also for converting scripts.

From IE Developer Tools

Also, Paul Way has shown that you can access the Xrm.Page object from the Developer Tools console window using the following code.

frames[0].Xrm.Page

CRM 4 to CRM 2011 JavaScript Converter Tool

This project is superceded by the new application Dynamics XRM Tools which includes improved features http://dynamicsxrmtools.codeplex.com/

Here I have a CRM 4 to CRM 2011 Javascript Converter tool that helps convert scripts to the latest CRM 2011 Form scripting model. The converter uses an xml file that contains CRM4 and CRM5 nodes which allow the converter to find/replace specific instances of text.

I created this as an aid to help me during upgrades from CRM 4 to CRM 2011, so if you would like to test it against your CRM 2011 javascript web resources after you upgrade from CRM 4 then let me know how it goes.

You can find the tool on codeplex here.

CRM 4 to CRM 2011 JavaScript Converter Tool

CRM 4 to CRM 2011 JavaScript Converter Tool

Has this Tool saved you time…

If you have benefited from downloading and using this tool, please feel free to donate an amount of your choice. Thankyou

GBP – Donate via PayPal - GBP>

USD – Donate via PayPal - USD>

Euro – Donate via PayPal - Euro>

Microsoft Dynamics CRM 2011 – Hide Areas of a Form

These code snippets will hide specific areas of the Form.


// Toggle the Ribbon Toolbar to Show/Hide (same as clicking the show/hide Ribbon button)
window.top.document.getElementById("minimizeribbon").fireEvent("onclick");

// Hide the Ribbon Toolbar and move the form Content area to the top of the window.
window.top.document.getElementById("crmTopBar").style.display = "none";
window.top.document.getElementById("crmContentPanel").style.top = "0px"; // Move Form Content area up to top of window, initial style.top is 135px

// Hide Left Hand Nav bar / pane
document.getElementById("crmNavBar").parentElement.style.display = "none";
document.getElementById("tdAreas").parentElement.parentElement.parentElement.parentElement.colSpan = 2;

// Hide the Breadcrumb and Record Set Toolbar
document.getElementById("recordSetToolBar").parentElement.style.display = "none";

// Hide the Form Footer Bar
document.getElementById("crmFormFooter").parentElement.style.display = "none";

 

Create Email Activity from Template using Javascript

Here is a nice piece of code to create an email from a specified email template using Javascript and also set the Email to field. Its slightly unrefined but good to go and a great starting point. It is great functionality if you choose to add a menu button to an entity in the ISV.config or similar and loads almost instantly.


//
// Create Email From template with the specified customer and regarding entity
//
CreateEmailFromTemplate = function(Customer, TemplateId, EntityId, EntityTypeName) {
// Generate an email activity from the specified template
//
var xml = "" +
"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" +
"&lt;soap:Envelope xmlns:soap=\"<a href="//schemas.xmlsoap.org/soap/envelope/\&quot;">http://schemas.xmlsoap.org/soap/envelope/\</a>" xmlns:xsi=\"<a href="//www.w3.org/2001/XMLSchema-instance\&quot;">http://www.w3.org/2001/XMLSchema-instance\</a>" xmlns:xsd=\"<a href="//www.w3.org/2001/XMLSchema\&quot;">http://www.w3.org/2001/XMLSchema\</a>"&gt;" +
GenerateAuthenticationHeader() +
" &lt;soap:Body&gt;" +
" &lt;Execute xmlns=\"<a href="//schemas.microsoft.com/crm/2007/WebServices\&quot;">http://schemas.microsoft.com/crm/2007/WebServices\</a>"&gt;" +
" &lt;Request xsi:type='InstantiateTemplateRequest' ReturnDynamicEntities='false' &gt;"+
" &lt;TemplateId&gt;" + TemplateId + "&lt;/TemplateId&gt;"+
" &lt;ObjectType&gt;" + EntityTypeName + "&lt;/ObjectType&gt;"+
" &lt;ObjectId&gt;" + EntityId + "&lt;/ObjectId&gt;"+
" &lt;/Request&gt;"+
" &lt;/Execute&gt;" +
" &lt;/soap:Body&gt;" +
"&lt;/soap:Envelope&gt;";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "<a href="//schemas.microsoft.com/crm/2007/WebServices/Execute&quot;">http://schemas.microsoft.com/crm/2007/WebServices/Execute</a>");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var entityNode = resultXml.selectSingleNode("//BusinessEntityCollection/BusinessEntities/BusinessEntity");
if(entityNode == null)
{
alert("Could not create email from template.");
return;
}
// Get the email details
var emailBody = entityNode.selectSingleNode("q1:description");
var subject = entityNode.selectSingleNode("q1:subject");
//
// Create email activity in CRM
//
var emailXml = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" +
"&lt;soap:Envelope xmlns:soap=\"<a href="//schemas.xmlsoap.org/soap/envelope/\&quot;">http://schemas.xmlsoap.org/soap/envelope/\</a>" xmlns:xsi=\"<a href="//www.w3.org/2001/XMLSchema-instance\&quot;">http://www.w3.org/2001/XMLSchema-instance\</a>" xmlns:xsd=\"<a href="//www.w3.org/2001/XMLSchema\&quot;">http://www.w3.org/2001/XMLSchema\</a>"&gt;" +
GenerateAuthenticationHeader() +
"&lt;soap:Body&gt;" +
"&lt;Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'&gt;" +
"&lt;entity xsi:type='email'&gt;" +
"&lt;description&gt;" + emailBody.text + "&lt;/description&gt;" +
"&lt;subject&gt;" + subject.text + "&lt;/subject&gt;" +
"&lt;regardingobjectid type='" + EntityTypeName + "'&gt;" + EntityId + "&lt;/regardingobjectid&gt;";
if(Customer != null)
emailXml = emailXml + "&lt;to&gt;&lt;activityparty&gt;&lt;partyid type='" + Customer[0].typename + "'&gt;" + Customer[0].id + "&lt;/partyid&gt;&lt;/activityparty&gt;&lt;/to&gt;";
emailXml = emailXml + "&lt;/entity&gt;" +
"&lt;/Create&gt;" +
"&lt;/soap:Body&gt;" +
"&lt;/soap:Envelope&gt;";
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "<a href="//schemas.microsoft.com/crm/2007/WebServices/Create&quot;">http://schemas.microsoft.com/crm/2007/WebServices/Create</a>");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(emailXml);
var resultEmailXml = xmlHttpRequest.responseXML;
// Check for errors.
var errorCount = resultEmailXml.selectNodes('//error').length;
if (errorCount &gt; 0)
{
alert("Could not create email due to error. ");
return;
}
var createNode = resultEmailXml.selectSingleNode("//CreateResult");
if(createNode == null)
{
alert("Could not create email.");
return;
}
// Display the email activity to the user.
var emailId = createNode.text;
window.open('/activities/email/edit.aspx?id={' + emailId + '}');
} // CreateEmailFromTemplate

You can use this function to retrieve a template id by specifying a template name/title.

//
// Retrieve the template's id value given the specified template name/title
//
GetTemplateIdByName = function(Name)
{
var id = null;
var xml = "" +
"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" +
"&lt;soap:Envelope xmlns:soap=\"<a href="//schemas.xmlsoap.org/soap/envelope/\&quot;">http://schemas.xmlsoap.org/soap/envelope/\</a>" xmlns:xsi=\"<a href="//www.w3.org/2001/XMLSchema-instance\&quot;">http://www.w3.org/2001/XMLSchema-instance\</a>" xmlns:xsd=\"<a href="//www.w3.org/2001/XMLSchema\&quot;">http://www.w3.org/2001/XMLSchema\</a>"&gt;" +
GenerateAuthenticationHeader() +
" &lt;soap:Body&gt;" +
" &lt;RetrieveMultiple xmlns=\"<a href="//schemas.microsoft.com/crm/2007/WebServices\&quot;">http://schemas.microsoft.com/crm/2007/WebServices\</a>"&gt;" +
" &lt;query xmlns:q1=\"<a href="//schemas.microsoft.com/crm/2006/Query\&quot;">http://schemas.microsoft.com/crm/2006/Query\</a>" xsi:type=\"q1:QueryExpression\"&gt;" +
" &lt;q1:EntityName&gt;template&lt;/q1:EntityName&gt;" +
" &lt;q1:ColumnSet xsi:type=\"q1:ColumnSet\"&gt;" +
" &lt;q1:Attributes&gt;" +
" &lt;q1:Attribute&gt;templateid&lt;/q1:Attribute&gt;" +
" &lt;/q1:Attributes&gt;" +
" &lt;/q1:ColumnSet&gt;" +
" &lt;q1:Criteria&gt;" +
" &lt;q1:FilterOperator&gt;And&lt;/q1:FilterOperator&gt;" +
" &lt;q1:Conditions&gt;" +
" &lt;q1:Condition&gt;" +
" &lt;q1:AttributeName&gt;title&lt;/q1:AttributeName&gt;" +
" &lt;q1:Operator&gt;Equal&lt;/q1:Operator&gt;" +
"&lt;q1:Values&gt;" +
"&lt;q1:Value xsi:type='xsd:string'&gt;" + Name + "&lt;/q1:Value&gt;" +
"&lt;/q1:Values&gt;" +
" &lt;/q1:Condition&gt;" +
" &lt;/q1:Conditions&gt;" +
" &lt;/q1:Criteria&gt;" +
" &lt;/query&gt;" +
" &lt;/RetrieveMultiple&gt;" +
" &lt;/soap:Body&gt;" +
"&lt;/soap:Envelope&gt;";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "<a href="//schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple&quot;">http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple</a>");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
if(entityNode.selectSingleNode("q1:templateid") != null)
id = entityNode.selectSingleNode("q1:templateid").text;
return id;
} // GetTemplateIdByName

The following code provides an example of a function that can be called to execute the above functionality. The example assumes you have placed all of the code from this article in the Case's onload event. You can then call the ShowCaseEmailTemplate() function from an ISV.config button or wherever you choose to decide you need it.

//
// Creates and displays an email for a Case
//
ShowCaseEmailTemplate = function()
{
var templateId = GetTemplateIdByName("MyEmailTemplate");
if(templateId != null &amp;&amp; crmForm.ObjectId != null &amp;&amp; crmForm.all.customerid.DataValue != null)
CreateEmailFromTemplate(crmForm.all.customerid.DataValue, templateId, crmForm.ObjectId, "incident");
} // ShowCaseEmailTemplate