SetState for CustomEntity in CRM


For every new custom entity created in CRM corresponding SetStateCustomEntityNameRequest and SetStateCustomEntityNameResponse class gets created which we can use to set their status.

 

In the below example we have set the status inactive for our custom country entity records.

 

 

 SetStateNew_CountryRequest myCountryRequest = new SetStateNew_CountryRequest();

                // guid of the record to be deactivated

                myCountryRequest.EntityId = new Guid(“3AE10D22-60E4-DD11-9D85-00164145E126”);

                // statecode – 1 , statecodename- Inactive, statuscode – 2, statuscodename – Inactive

                // statecode – 0 , statecodename- Inactive, statuscode – 1, statuscodename – Inactive

                myCountryRequest.New_CountryState = New_CountryState.Inactive;

                myCountryRequest.New_CountryStatus = 2;

                SetStateNew_CountryResponse myCountryResponse = (SetStateNew_CountryResponse)crmService.Execute(myCountryRequest);

 

Bye ..

Programmatically updating the status of workflow logs using TargetUpdateWorkflowLog class in CRM 4.0


I was just trying out if changing the status for the workflow is possible programmatically. Well this is something I tried.

Created a function which would take primary key(guid) of the entity intance and would return all the workflow logs for that entity instance having status as “In Progress” and changing their status to “Failed”

 

The function to retrieve all the workflowlog id

 

private ArrayList   GetInProgressWorkflowLogIDForEntity(CrmService crmService, string EntityId)

        {

            QueryExpression myQuery = new QueryExpression();

            ColumnSet myCols = new ColumnSet();

            // to retireve workflowlogid

            myCols.Attributes = new String[] { “workflowlogid” };

            myQuery.ColumnSet = myCols;

            myQuery.EntityName = EntityName.workflowlog.ToString();

          

            ConditionExpression myCondtionExpression1 = new ConditionExpression();

            // entityinstance id against which workflowlog is running

            myCondtionExpression1.AttributeName = “regardingobjectid”;

            myCondtionExpression1.Operator = ConditionOperator.Equal;

            myCondtionExpression1.Values = new object[] {EntityId };

            // Status of workflowlog

            // Failed – 3

            // Succeeded – 2

            // In Progress – 1

            ConditionExpression myCondtionExpression2 = new ConditionExpression();

            myCondtionExpression2.AttributeName = “In Progress”;

            myCondtionExpression2.Operator = ConditionOperator.Equal;

            myCondtionExpression2.Values = new object[] { “1” };

 

            FilterExpression myFilterExpression = new FilterExpression();

            myFilterExpression.FilterOperator = LogicalOperator.And;

            myFilterExpression.Conditions = new ConditionExpression[] { myCondtionExpression1, myCondtionExpression2 };

 

            myQuery.Criteria = myFilterExpression;

 

            BusinessEntityCollection myBE=crmService.RetrieveMultiple(myQuery);

 

            ArrayList myWFLogList = new ArrayList();

            foreach (BusinessEntity myBusinessEntity in myBE.BusinessEntities)

            {

                workflowlog myWFLogId = (workflowlog)myBusinessEntity;

                myWFLogList.Add(myWFLogId.workflowlogid.Value.ToString());

 

            }

            return myWFLogList;    

        }

 

 

 

 

Using TargetUpdateWorkflowLog class

 

 

ArrayList myWorkflowLog=GetInProgressWorkflowLogIDForEntity(crmService, “55B93CBB-99E3-DD11-9D85-00164145E126”);

 

                foreach (String wfLogId in myWorkflowLog)

                {

                    TargetUpdateWorkflowLog myUpdateWorkflow = new TargetUpdateWorkflowLog();

                    myUpdateWorkflow.WorkflowLog = new workflowlog();

                    myUpdateWorkflow.WorkflowLog.workflowlogid = new Key();

                    // workflowlogid of workflow having status as In Progress

                    // to be changed to Failed – 3

                    myUpdateWorkflow.WorkflowLog.workflowlogid.Value = new Guid(wfLogId);

 

                    // Failed – 3

                    // Succeeded – 2

                    // In Progress – 1

                    myUpdateWorkflow.WorkflowLog.status = new Picklist();

                    myUpdateWorkflow.WorkflowLog.status.name = “Failed”;

                    myUpdateWorkflow.WorkflowLog.status.Value = 3;

 

                    UpdateRequest myRequest = new UpdateRequest();

                    myRequest.Target = myUpdateWorkflow;

 

                    UpdateResponse myRes = (UpdateResponse)crmService.Execute(myRequest);

                }

           

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.