This post is about how to use the "ExecuteMultipleRequest" message to resolve cases in Bulk.
The main advantage is that if you have to update thousands of record you can do that by sending one single server request and not thousands of requests as it happens with the single Request.
This particular example is for changing the state and status of cases. To achieve that you have to use the "CloseIncidentRequest" message.
The "ExecuteMultipleRequest" message allows us to create a collection of "CloseIncidentRequest" requests and send it to the server to be processed.
Let's start off by creating a "ExecuteMultipleRequest" object:
var myMultipleRequest = new ExecuteMultipleRequest()
{
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = true,
ReturnResponses = false
},
Requests = new OrganizationRequestCollection()
};
And then we can loop through our list of cases to create a "CloseIncidentRequest" for each case.
I used a helper method to build the CloseIncidentRequest called "BuildIncidentResolutionRequest"
which takes the incident id and the status reason as input:
foreach (var incident in cases.Entities)
{
var closeIncidentRequest = BuildIncidentResolutionRequest(incident.Id, caseStatusReason);
myMultipleRequest.Requests.Add(closeIncidentRequest);
}
This method first creates a new Entity (which is an activity of type Case Resolution) called "incidentresolution" which will be used in the "CloseIncidentRequest" this entity is used to resolve the incident and a subject and description can be provided.
Note: If you try to resolve a case using the UI you must enter a resolution (which is the subject) that information will be held in the entity called "incidentresolution" which can be viewed in CRM with an advanced find or in the closed activities linked to the case. An "incidentresolution" record will be created for each case you are resolving.
It then creates the "CloseIncidentRequest".
private CloseIncidentRequest BuildIncidentResolutionRequest(Guid incidentId, int caseStatusReason)
{
// Create the incident's resolution.
var incidentResolution = new Entity("incidentresolution");
incidentResolution["subject"] = "Case was Resolved";
incidentResolution["incidentid"] = new EntityReference("incident", incidentId);
incidentResolution["description"] = "Description";
// Close the incident with the resolution.
var closeIncidentRequest = new CloseIncidentRequest
{
IncidentResolution = incidentResolution,
Status = new OptionSetValue(caseStatusReason)
};
return closeIncidentRequest;
}
...and finally the list of requests is sent to the server to be processed.
var responses = (ExecuteMultipleResponse)orgService.Execute(myMultipleRequest);
We can also assert if any error occurred by checking the "IsFaulted" flag.
Anyway for more information refer to the msdn this page.
if (responses.IsFaulted)
{
Console.WriteLine("Error: {0}", myMultipleRequest.Responses[0].Fault.Message);
}
A Blog about my experience with Microsoft Dynamics CRM as developer.
Featured Post
Web API Requests Series
Web API Series: Create and Retrieve , Update and Delete , Retrieve Multiple , Associate/Disassociate , Impersonation , Run Workflows
Showing posts with label crm 2011. Show all posts
Showing posts with label crm 2011. Show all posts
25 February 2015
13 April 2012
How to assign a record to another User in CRM 2011
In this brief post I will show you how to set the Owner of a record in C#, in other words how to assign a record to a User.
To assign a record an Owner you have to send an Assign Request using the Execute method.
service.Execute(new AssignRequest()
{
Assignee = new EntityReference("systemuser", userId),
Target = new EntityReference(updateEntity, recordId)
}
);
The Assign Request has two properties:
Hope this helps.
To assign a record an Owner you have to send an Assign Request using the Execute method.
service.Execute(new AssignRequest()
{
Assignee = new EntityReference("systemuser", userId),
Target = new EntityReference(updateEntity, recordId)
}
);
The Assign Request has two properties:
- Assignee: This can be either a Team or a User.
- Target: this is the record you want to assign.
Hope this helps.
19 March 2012
How to pass parameters from subgrids to JavaScript
In this post I will show you how to pass parameters regarding a grid or subgrid to a JavaScript function by clicking a custom button on the ribbon menu.
A common requirement is to pass poarameters to a JavaScript function called when clicking a Ribbon button.
To pass parameters regarding a grid or a subgrid we can use the "crmparameter" element of the RibbonDiffXml file.
The available parameters can be devided in three groups:
<CommandDefinition Id="Mscrm.SubGrid.opportunity.Command">
<EnableRules>
<EnableRule Id="Mscrm.SubGrid.opportunity.EnableRule"></EnableRule>
</EnableRules>
<DisplayRules></DisplayRules>
<Actions>
<JavaScriptFunction Library="$webresource:functions.js" FunctionName="MyFunction" >
<CrmParameter Value="SelectedControlSelectedItemIds" />
<CrmParameter Value="SelectedControlSelectedItemCount" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
To access these parameters add them to your function definition like below:
function MyFunction(SelectedControlSelectedItemIds, SelectedControlSelectedItemCount) {
for (i = 0; i < SelectedControlSelectedItemCount; i++) {
}
}
So as you can see it is possible to access records displayed in a subgrid using supported code, so don't get tempted to use document.getElementById. ;)
I hope this help.
A common requirement is to pass poarameters to a JavaScript function called when clicking a Ribbon button.
To pass parameters regarding a grid or a subgrid we can use the "crmparameter" element of the RibbonDiffXml file.
The available parameters can be devided in three groups:
- Selected items
- SelectedControlSelectedItemCount: The number of selected items in a grid or subgrid.
- SelectedControlSelectedItemIds: A string array of GUID Id values for all selected items in a grid.
- SelectedControlSelectedItemReferences: An array of EntityReference objects that represent all the selected items in the grid
- All items
- SelectedControlAllItemCount: The number of items in a grid or subgrid.
- SelectedControlAllItemIds: A string array of GUID Id values for all items in a grid.
- SelectedControlAllItemReferences: An array of EntityReference objects that represent all the items in the grid.
- Unselected items
- SelectedControlUnselectedItemCount: The number of unselected items in a grid or subgrid.
- SelectedControlUnselectedItemIds: A string array of GUID Id values for all unselected items in a grid.
- SelectedControlUnselectedItemReferences: An array of EntityReference objects that represent all the unselected items in the grid.
<CommandDefinition Id="Mscrm.SubGrid.opportunity.Command">
<EnableRules>
<EnableRule Id="Mscrm.SubGrid.opportunity.EnableRule"></EnableRule>
</EnableRules>
<DisplayRules></DisplayRules>
<Actions>
<JavaScriptFunction Library="$webresource:functions.js" FunctionName="MyFunction" >
<CrmParameter Value="SelectedControlSelectedItemIds" />
<CrmParameter Value="SelectedControlSelectedItemCount" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
To access these parameters add them to your function definition like below:
function MyFunction(SelectedControlSelectedItemIds, SelectedControlSelectedItemCount) {
for (i = 0; i < SelectedControlSelectedItemCount; i++) {
}
}
So as you can see it is possible to access records displayed in a subgrid using supported code, so don't get tempted to use document.getElementById. ;)
I hope this help.
11 January 2012
How to retrieve all the activities for a record
In this post I will show how to retrieve all the activities in which a record is related to as:
Here is the query:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="prioritycode" />
<attribute name="modifiedon" />
<attribute name="activityid" />
<attribute name="instancetypecode" />
<order attribute="modifiedon" descending="false" />
<link-entity name="activityparty" from="activityid" to="activityid" alias="aa">
<filter type="and">
<condition attribute="participationtypemask" operator="in">
<value>4</value>
<value>3</value>
<value>11</value>
<value>6</value>
<value>7</value>
<value>9</value>
<value>8</value>
<value>5</value>
<value>10</value>
<value>1</value>
<value>2</value>
</condition>
<condition attribute="partyid" operator="eq" uitype="contact" value="Xrm.Page.data.entity.getId()" />
</filter>
</link-entity>
</entity>
</fetch>
The corresponding advanced find query is:
Hope this helps,
Luciano.
- BBC Recipient
- CC Recipient
- Customer Optional Attendee
- Organizer
- Owner
- Regarding
- Required attendee
- Resource
- Sender
- To Recipient
Here is the query:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="prioritycode" />
<attribute name="modifiedon" />
<attribute name="activityid" />
<attribute name="instancetypecode" />
<order attribute="modifiedon" descending="false" />
<link-entity name="activityparty" from="activityid" to="activityid" alias="aa">
<filter type="and">
<condition attribute="participationtypemask" operator="in">
<value>4</value>
<value>3</value>
<value>11</value>
<value>6</value>
<value>7</value>
<value>9</value>
<value>8</value>
<value>5</value>
<value>10</value>
<value>1</value>
<value>2</value>
</condition>
<condition attribute="partyid" operator="eq" uitype="contact" value="Xrm.Page.data.entity.getId()" />
</filter>
</link-entity>
</entity>
</fetch>
The corresponding advanced find query is:
Hope this helps,
Luciano.
30 May 2011
How to use the CSDL file generated by the REST endpoint with Silverlight.
In this walk through, I will walk you through the steps needed to download the CSDL file that the REST endpoint generates based on the entities available to your development organization. Later we will see how to create a WCF data service based on the CSDL file.
N.B. Only those entities that are present when you generate the classes will be available for the Silverlight application.
Steps:
- In CRM 2011 navigate to Settings. Choose Customizations and then Developer Resources.
- Under Service Endpoints, click the Download CSDL link and save the OrganizationData.csdl file to your computer.
Now that we have our file generated and downloaded to our computer, we can use it to create a WCF data service, so from Visual Studio:
- In your Visual Studio Silverlight application project, right-click References, and then click Add Service Reference.
- Type the path of the location where you saved the OrganizationData.csdl file, and then click Go.
- Enter an appropriate Namespace and then click OK.
Well done! Now we have our Silverlight application all set up ready to access the entities in our CRM organization. In another post I will show how to use the REST endpoint with Silverlight.
Stay tuned!
03 May 2011
Add Silverlight to an entity form Navigation Menu.
...another way to get advantage of the power of Silverlight within Crm 2011 is to use the whole entity form real estate. We can do this by adding a navigation item to an existing group. The navigation area is divided into five areas: Common, Sales, Service, Marketing and for entities that support them, Processes, We can either use the form editor using drag and drop to change their vertical position, add new items, move existing items to another area or use the "FormXml" element (I will talk about how to customise the FormXml element in another post) to achieve the same result.
N.B. "In Microsoft Dynamics CRM 2011 , the ability to add navigation items to the entity form has been moved from ISV.Config to the <FormXml> (FormXML) element for each entity form. During upgrade from Microsoft Dynamics CRM 4.0, any entity form navigation customizations in the ISV.Config are moved to the definition of the main form for that entity."
So, let's see how we can customise an entity navigation form; first of all we are going to add a new navigation item to an existing area (it is not possible to add a new area). Open an entity record select the Customize tab and click on "Form",
this will open the form editor, at this point click on "Navigation" select the area on the navigation menu that you want to customise,
select the "Insert" tab,
and click the Navigation Link button,
Select a name, look up for an icon and the HTML web resource that hosts your Silverlight application that you have previously added.
And here is the final result.
Hope you enjoyed. :)
N.B. "In Microsoft Dynamics CRM 2011 , the ability to add navigation items to the entity form has been moved from ISV.Config to the <FormXml> (FormXML) element for each entity form. During upgrade from Microsoft Dynamics CRM 4.0, any entity form navigation customizations in the ISV.Config are moved to the definition of the main form for that entity."
So, let's see how we can customise an entity navigation form; first of all we are going to add a new navigation item to an existing area (it is not possible to add a new area). Open an entity record select the Customize tab and click on "Form",
this will open the form editor, at this point click on "Navigation" select the area on the navigation menu that you want to customise,
select the "Insert" tab,
and click the Navigation Link button,
Select a name, look up for an icon and the HTML web resource that hosts your Silverlight application that you have previously added.
And here is the final result.
Hope you enjoyed. :)
Subscribe to:
Posts (Atom)






