Monday, 30 November 2009

How to call/launch/execute workflow and wait until its execution to make some action with JavaScript in Microsoft Dynamics CRM

from here: http://a33ik.blogspot.com/2009/09/how-to-calllaunchexecute-workflow-and.html

Author of code for workflow executing is Jian Wang. I wrote a code that waits for the workflow to be completed.

So the code:

ExecuteWorkflow = function(entityId, workflowId)

{
var xml = "" +
"\"1.0\" encoding=\"utf-8\"?>" +
"\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" " +
" \"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" \"ExecuteWorkflowRequest\">" +
" " + entityId + "" +
" " + workflowId + "" +
"
"
+
"
"
+
" " +
"
"
+
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return(resultXml.selectSingleNode('//soap:Envelope/soap:Body/ExecuteResponse/Response/Id').nodeTypedValue);
}

WaitWorkflowExecution = function(workflowId)
{
var xml = ""+
"+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
GenerateAuthenticationHeader() +
""+
""+
"asyncoperation"+
""+workflowId+""+
""+
""+
"statuscode"+
""+
""+
""+
""+
"
"
;

var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
var resultXml = xHReq.responseXML;

var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0)
{
setTimeout("WaitWorkflowExecution('" + workflowId + "');", 1000);

}
else
{
var executionstatus = resultXml.selectSingleNode("//soap:Envelope/soap:Body/RetrieveResponse/RetrieveResult/q1:statuscode").nodeTypedValue;


if (executionstatus == 30)//Workflow completed
{
alert("Workflow Completed!");
}
else
{
setTimeout("WaitWorkflowExecution('" + workflowId + "');", 1000);
}
}
}

var theWorkflowId = "6eb47269-4139-40b3-a96d-255ef2d78e6a"; //change to your workflow Id
var workflowInstanceId = ExecuteWorkflow(crmForm.ObjectId, theWorkflowId);

WaitWorkflowExecution(workflowInstanceId);

How to restict users from entering special characters in Microsoft Dynamics CRM 4.0

From here: http://a33ik.blogspot.com/2009/09/how-to-restict-users-from-entering.html

Solution is very simple - just add following script to OnLoad event handler of form:


function SwitchOnCheck(ElementId)
{
var element = document.getElementById(ElementId);
if (element != null)
element.attachEvent("onkeyup", function()
{
var mikExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/;
var strPass = element.value;
if (strPass == null)
return;
var strLength = strPass.length;
var lchar = element.value.charAt(strLength - 1);
while(lchar.search(mikExp) != -1)
{
strPass = strPass.substring(0, strLength - 1);
if (strPass.length == 0)
break;
strLength = strPass.length;
lchar = strPass.charAt(strLength - 1);
}

element.value = strPass;
});
}

Clearing fields in Microsoft Dynamics CRM 4.0

credit where it's due: http://a33ik.blogspot.com/2009/11/clearing-fields-in-microsoft-dynamics.html


...used following code to clear fields (set properties of entities to null):

account acc = new account();
acc.accountid = new Key(new Guid("249FB2CF-31CD-DE11-AB59-005056B30605"));

Lookup lookup = new Lookup();
lookup.IsNull = true;
lookup.IsNullSpecified = true;

acc.primarycontactid = lookup;
crmservice.Update(acc);


This code works but there is more elegant and readable way to clear fields:

account acc = new account();
acc.accountid = new Key(new Guid("249FB2CF-31CD-DE11-AB59-005056B30605"));
acc.primarycontactid = Lookup.Null;
crmservice.Update(acc);


Similar approach also will work for CrmDateTime, CrmNumber, Picklist, Customer, CrmMoney, CrmFloat, CrmDecimal fields.

Wednesday, 25 November 2009

Add field Tooltips

crmForm.all.new_attribute_c.title = “contents of the tooltip”

http://crm.atechnisch.nl/2009/07/use-tooltips-as-hot-help/

Friday, 13 November 2009

Dynamics CRM 4.0: Placing an Associated View in an iFrame

Update to the Dynamics CRM Statement of Direction

Security and Authentication in Microsoft Dynamics CRM: Field-level Security in Microsoft Dynamics CRM: Options and Constraints

Wednesday, 11 November 2009

Pseudo-Filtered Lookup Dialog in Microsoft Dynamics CRM 4.0

Monday, 9 November 2009

Using Filters in a Report

Walkthrough: Creating and Registering a Custom Workflow Activity

Microsoft Dynamics CRM SDK 4.0.10 is available

Creating a Custom Search Button

Overriding Records per page count for Microsoft Dynamics CRM 4.0

Monday, 2 November 2009

Developer Ramp up Kit for Microsoft Dynamics CRM 4.0