Understanding inputparameters and outputparameters of plugin context in CRM4.0


I was wondering what inputparameters and outparameters are passed by the platform to the IPluginExecutionContext’s context. Just created a simple plugin and registered it for (Pre/Post)Create,Update, Delete event of lead. And debugged it in visual studio to know the values for these parameters

InputParameters will have the parameters of the request message whi ch triggered the event i.e Represents the data that was passed along with the request to the platform. It will have two keys Target and OptionalParameters

Target property will be passed as a DynamicEntity and represents the image of the data passed.

OutputParameters is populated by the platform and only contains valid data during the After

Operation stage. This will contain the properties of the response message. The most common property returned is an “id” entry that will represent the Guid. In that example, it works exactly the same way the Request will produce a Response object with an id property. You would use this value to do subsequent processing that you need the entity Id value to be able to relate data.

OutputParameters will have the properties of the response message which is returned as part of pipeline execution. It will have one key OptionalParameters.

For PreCreate

Inputparameters – Two key – Target and OptionalParameters

Target – It had 35 properties basically one for all the attributes with its corresponding values

For optional parameters it had following value
CreateDuplicatesOptionalParameters with the value as false.

For PostCreate.

InputParameters – Target – same 35 properties for each attribute.

OutputParameters – Had one key – id with values of the newly created lead.

For PreUpdate

InputParameters – It had attributes whose values have been modified , leadid (primarykey of lead) as well those attributes that have forceSubmit true.

CreateDuplicatesOptionalParameters with the value as false.

Outputparameters – Nothing in output parameters

For PostUpdate

InputParameters – It had attributes whose values have changed, leadid (primarykey of lead), as well those attributes that have forceSubmit true.

CreateDuplicatesOptionalParameters with the value as false.

Outputparameters – Nothing in output parameters.

For PreDelete

Target was of type -Microsoft.Crm.Sdk.Moniker having Id of the record to be deleted and name as entity name – lead

For create,update message Target property was -Microsoft.Crm.Sdk.DynamicEntity.

Nothing in OptionalParameters

Outputparameters – Nothing in output parameters.

For PostDelete

Target was of type –Microsoft.Crm.Sdk.Moniker having Id of the record to be deleted and name as lead

Nothing in OptionalParameters

Outputparameters – Nothing in output parameters.

 

To know more about inputparameters and outputparameters

http://www.patrickverbeeten.com/pages/ContentItemPage.aspx?id=12&item=53&p=true

Bye..

Advertisements

Error : Url does not contain MSCRMServices


I got this error while using Accessing Microsoft Dynamics CRM Web Services from onload of lead entity.

I used the sample given in SDK which calls the WhoAmI message with the Execute method to retrieve the ID of the current user.

Resolved the error by replacing the url

xmlhttp.open(‘POST’, SERVER_URL +’/mscrmservices/2007/crmservice.asmx’, false);

to

xmlhttp.open(“POST”,  “http://myServerName:Port/MSCrmServices/2007/CrmService.asmx”, false);

SERVER_URL  global variable actually returns

http://myServerName:Port/organizationname because of which we got the error.

Here is the final code that I used

//Define the soapBody for the WhoAmI request.

var soapBody = “<soap:Body><Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’><Request xsi:type=’WhoAmIRequest’ /></Execute></soap:Body>”;

//Wrap the Soap Body in a soap:Envelope.

var soapXml = “<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/&#8217; xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance&#8217; xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>&#8221;;

soapXml += GenerateAuthenticationHeader();

soapXml += soapBody;

soapXml += “</soap:Envelope>”;

// Create the XMLHTTP object for the execute method.

var xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);

xmlhttp.open(“POST”, http://d-3638:5555/MSCrmServices/2007/CrmService.asmx&#8221;, false);

xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

xmlhttp.setRequestHeader(“SOAPAction”, http://schemas.microsoft.com/crm/2007/WebServices/Execute&#8221;);

//Send the XMLHTTP object.

xmlhttp.send(soapXml);

// Create an XML object to parse the results.

xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);

xmlDoc.async=false;

xmlDoc.loadXML(xmlhttp.responseXML.xml);

// Get the user’s ID.

var userid = xmlDoc.getElementsByTagName(“UserId”)[0].childNodes[0].nodeValue;

Bye..


Developer ramp up for MOSS (SharePoint) and Microsoft Dynamics CRM 4.0


The best place for someone starting with development in Microsoft Dynamics CRM 4.0 and MOSS development.

SharePoint Developer RampUp

Microsoft Dynamics CRM 4.0

Other Ramp Up

Bye…

New Events or Messages for Plug-ins in CRM 4.0


In CRM 3.0, following were the events against which we could have written our callouts

Pre/Post – Create, Update, Delete, Assign, SetState, Merge.

PreSend, PostDeliver.

In CRM 4.0, the above event are now referred as messages for plug-ins. All the above events that were in CRM 3.0 are there as well as there many new messages/events have been added against which plug-ins can be attached.

For e.g. we can attach a plug-in against AddMembers message for team entity which would fire when we are adding members to a team.or attach a plug-in against Retrieve message for say lead entity which would fire when retrieve method of CrmService is used.

We can find all the new messages and the entities on which they work in SDK.

Executing CRM Workflow programmatically from an external application. CRM 4.0 using ExecuteWorkflowRequest


There is a method named ExecuteWorkflowRequest using which we can execute our workflow programmatically. We had a requirement to find all the opportunities which haven’t been modified for past 30 days and to decrease their probability attribute value by 10.

Now the thing over here was that there wasn’t any specific event against which we could have fired the above workflow. So we thought of writing an application which than we could scheduled, which will periodically run the above workflow

This is how we implemeneted it within a windows application

private void Form1_Load(object sender, EventArgs e){

CrmAuthenticationToken token = new CrmAuthenticationToken();

token.OrganizationName = “organizationName”;

//0 – AD

//1 – Passport

//2 – Form Authentication

token.AuthenticationType = 0;

CrmService crmService = new CrmService();

crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

crmService.CrmAuthenticationTokenValue = token;

crmService.Url = http://servername:port/mscrmservices/2007/crmservice.asmx&#8221;;

try{

// Create an ExecuteWorkflow request.

ExecuteWorkflowRequest request = new ExecuteWorkflowRequest();

//Assign the ID of the workflow you want to execute to the request.

// use this query to get the id select parentworkflowid,name,* from dbo.Workflow

// id is the parentworkflowid

request.WorkflowId = new Guid(“21B9528D-D13D-4B93-9F91-FA7468D3C82C”);

// We want to run it against all the opportunity which are in open state

ArrayList OpportunityGuids = GetOpportunityGuids(crmService);

foreach (String oppGuid in OpportunityGuids){

//Assign the ID of the entity to execute the workflow on to the request.

request.EntityId = new Guid(oppGuid);

ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)crmService.Execute(request);}

// Execute the workflow. }

catch (SoapException ex){

// write in log}

catch (Exception ex){

// write in log} }

private ArrayList GetOpportunityGuids(CrmService crmService){

// using QueryByAttribute to retrieve all the opportunity having statuscode as 1 i.e. Open

QueryByAttribute myOppQuery = new QueryByAttribute();

myOppQuery.Attributes = new String[] { “statuscode” };

myOppQuery.Values = new String[] {“1”};

ColumnSet myCols = new ColumnSet();

myOppQuery.ColumnSet = myCols;

myOppQuery.EntityName = EntityName.opportunity.ToString();

WindowsFormsApplication2.CrmSdk.BusinessEntityCollection myOppCollection= crmService.RetrieveMultiple(myOppQuery);

ArrayList opportunityGuids = new ArrayList();

foreach (WindowsFormsApplication2.CrmSdk.BusinessEntity opp in myOppCollection.BusinessEntities ){

opportunity myOpp = (opportunity)opp;

opportunityGuids.Add(myOpp.opportunityid.Value.ToString()); }

return opportunityGuids;

}

Bye ..

Error: The request failed with HTTP status 401 or Error 401.2: Unauthorized while using CrmService in ASP.NET or windows application CRM 4.0


To use CrmService or Metadata Service (CRM 4.0) within an ASP.NET page or a windows application we need to make use of CRM Authentication token.If we are using Active Directory Authentication this is the code for that

CrmAuthenticationToken token = new CrmAuthenticationToken();

token.OrganizationName = “organizationName”;

//0 – AD

//1 – Passport

//2 – Form Authentication

token.AuthenticationType = 0;

CrmService service = new CrmService();

service.Credentials =System.Net.CredentialCache.DefaultCredentials;

service.CrmAuthenticationTokenValue = token;

service.Url = http://servername:port/mscrmservices/2007/crmservice.asmx&#8221;;

try{

WhoAmIRequest myReq = new CrmSdk.WhoAmIRequest();

WhoAmIResponse myResp = (CrmSdk.WhoAmIResponse)service.Execute(myReq);

}

catch (SoapException ex){

Response.Write(ex.Detail.InnerText);

}

catch (Exception ex){

Response.Write(ex.Message);}

 

If we get the above unauthorized access error it could be because either there is problem in our CrmAuthenticationToken, may be we could have assigned wrong organization name or authentication type. If we are using CrmService in an ASP.NET page than we need to use impersonation.

 

<authentication mode=Windows/>

<identity impersonate=true/>

 

If we are using 2006 end point of CrmService we don’t have to use CrmAuthenticationToken.