Monday, December 27, 2010

Client-side scripting example for RetrieveMultiple

When a new case is created generate a case number, instead of using the "auto-numbering", so that you can put it in any format you want. I wanted our case number to be all numeric, and be sequential. In other words, I wanted to create new cases with case number = last case number + 1.

Client-side code
In the Case form OnLoad event (under form properties)  add the following javascript:
Note: This client-side code is the almost equivalent to the SQL statement: SELECT TOP 1 ticketnumber + 1 FROM IncidentBase ORDER BY createdon DESC

if(crmForm.FormType == CRM_FORM_TYPE_CREATE)
// Prepare variables to retrieve the contacts.
var msg = "";
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>"+
"<soap:Envelope xmlns:soap=''"+
" xmlns:xsi=''"+
" xmlns:xsd=''>"+
"<RetrieveMultiple xmlns=''>"+
"<query xmlns:q1=''"+
" xsi:type='q1:QueryExpression'>"+
"<q1:ColumnSet xsi:type='q1:ColumnSet'>"+
"<q1:Orders>" +
"<q1:Order>" +
"<q1:AttributeName>createdon</q1:AttributeName>" +
"<q1:OrderType>Descending</q1:OrderType>" +
"</q1:Order>" +
"</q1:Orders>" +
"<q1:PageInfo>" +
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount !== 0)
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
// Parse and display the results.
var results = resultXml.getElementsByTagName('BusinessEntity');
var msg = "";
if (results.length === 0)
msg = "Unable to generate case number, please fill in the Case Number field manually";
crmForm.all.ticketnumber.disabled = false;
var ticketnumber= results[0].selectSingleNode('./q1:ticketnumber').nodeTypedValue;
var strArr = ticketnumber.split('-');
var index = 0;
if(strArr.length > 1)
index = 1;
var tickNum = new Number(strArr[index]);
crmForm.all.ticketnumber.value = new Number(tickNum + 1);
msg = "Case number found was not a number, please fill in the Case Number field manually";
crmForm.all.ticketnumber.disabled = false;

1. Server-side translation into client-side JavaScript
2. Example of attributes for an entity (incident):

Tuesday, December 21, 2010

Unable to publish workflow - Dynamics CRM 4.0

You cannot publish Workflows in Dynamics CRM 4.0, and you get the following message in the event viewer: "Exception has been thrown by the target of an invocation."

1. Open the CRM website's web.config. (typically located in C:\Inetpub\wwwroot)

2. Locate section <authorizedTypes>

3. Add the following to this section:
<authorizedType Assembly="mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Globalization" TypeName="CultureInfo" Authorized="True"/>

Friday, December 10, 2010

Two very useful tools for rebuilding a computer

DriverMax - Allows you to quickly see all of the drivers on your system, and then export them to a folder. This is useful because you can then slipstream the drivers into the OS installation, instead of having to download them all and add them from scratch.

nLite - Use it to build slipstreamed OS bootable ISO with customizations, such as adding drivers, creating an unattended installation, and more.

Boot and Nuke - This is used to completely erase data from hard drives.
There was an error in this gadget