Wednesday, July 28, 2010

Calling Custom Workflows In Javascript or ISV

If we want to calll Custom workflow with in CRM 4.0 javascript or ISV we call CRM 4.0 inbuilt function "launchOnDemandWorkflow" in this methods we can pass object ID and Workflow ID launchOnDemandWorkflow('',ObjectTypeCode,Workflow ID)

We simply get ObjectTypeCode from crmForm.Objectid and workflow is unigue ID we can get from Workflow section. the problems is that when we call this launchOnDemandWorkflow it will frompt workflow dialog box for our confirmation after that we can't put notification whether that workflow Successed or not. in this can we can remove this pfompt box and we can put custom confirmation message and success message.


/********************* Calling Custom Workflows ************************/
//Pirasanth
ExecuteWorkflow = function(entityId, workflowId)
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <Request xsi:type=\"ExecuteWorkflowRequest\">" +
" <EntityId>" + entityId + "</EntityId>" +
" <WorkflowId>" + workflowId + "</WorkflowId>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
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.xml);

}

/*************************Calling Web Services****************************/


this Wrokflow dialog box promf for confirmation if we press ok then ll execute the workflow bt user doesn't know this workflow successed or not..user can check from workflow section bt not ll promf


so in this case we can put custom confirmation messagebox and after scuuessed we can put notificatiopn whether theis workflow successed or no..
for the confirmation message we can put

Success Message..

Here user could understand whethere this workflow successed or not

Amma Bhagavan's Songs