Showing posts with label Pirasanth. Show all posts
Showing posts with label Pirasanth. Show all posts

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

Monday, March 22, 2010

Calling WCF Restful Services in Jquery

Create WCF 2010 Restful Services



Visual studio 2010 produce some online template so we can download this template and use from this online template we can get WCF REST Service Template 40(CS)

Just go to New Project - Online Templates - get WCF REST Service Template 40(CS) from this we can download restful service template. Once we download it will come under WCF directory.



Solutions look like this.







In this service1 class contain default methods some methods contain WebGet and WebInvoke. If we use WebGet work methods as get if we use WebInvoke we can specify methods as PUT, POST, DELETE depending on the situation we can use either WebGet or WebInvoke.



I wrote methods to return list of student details. Here UriTemplate is the URL for access this methods and response methods as JSON because I need to call this methods in Jquery so I use JSON format. Body style is not mandatory

<pre class="brush:html">

[WebGet(UriTemplate = "StudentsJSON",BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]

Public List<Student> GetStudentCollectionJSON()

{

return new Student().getStudent();



}



Main advantage of this REST in 4.0 is we can give unique URL for each method and in WCF there is no .SVC extension. Microsoft has removed this SVC extension.



From below URL we can see all the methods here there is no .svc extension

http://localhost/Test/TestService/help









Calling WCF Restful Services in Jquery



Before discuss about calling WCF Restful Services through Jquery we need to understand what is REST? Why we need to use restful services? When Microsoft introduces this REST and Restful services? Why we need to away from ASMX, WCF using SOAP base protocols? So here I am not going to explain the theory we can get to know by googling.



If we navigate through the methods “GET” we will get XML, JSON format default data







If we use http://localhost/Test/TestService/StudentsXML link we will get XML format data









[WebGet(UriTemplate = "StudentsXML" , ResponseFormat = WebMessageFormat.Xml)]

public List<Student> GetStudentCollectionXML()

{

return new Student().getStudent();

}

Using http://localhost/Test/TestService/StudentsJSON link we will get JSON format data





[WebGet(UriTemplate = "StudentsXML" , ResponseFormat = WebMessageFormat.Xml)]



public List<Student> GetStudentCollectionXML()

{

return new Student().getStudent();



}



//Pirasanth

Amma Bhagavan's Songs