In this webinar, our experts showcase a variety of demo use cases of how different components of the...
Users of Microsoft Dynamics CRM 2011 have many features they can draw on to improve their CRM experience and improve business processes. One great feature to explore is using Fetch XML in a workflow.
Let's dig in using a real business situation.
Scenario - How to determine if a Contract's Contract Lines have a particular Product.
Solution - Luckily Microsoft CRM 2011 provides the use of executing Fetch XML in a custom workflow. Using Fetch XML (or Query Expression) in a custom workflow allows you to set up your query to use as many relationship levels as required. The added benefit of using Fetch XML is that you can use Advance Find to set up your query and download the Fetch Statement without using any other tools.
1. Start by using the Advance Find view to set up your fetch statement.
2. Next click on the Download Fetch XML button from the ribbon and open the downloaded file to select the fetch statement.
3. Next set up your Custom Workflow using Visual Studio 2010. For brevity you can reference http://msdn.microsoft.com/en-us/library/gg328515.aspx (Create a Custom Workflow Activity)
4. In the Execute method set a string variable with your Fetch XML statement and use the Services' RetrieveMultiple method with a FetchExpression as its parameter.
5. Register your Custom Workflow using the Plugin Registration tool.
Now you have the ability to run your Custom Workflow and validate if a Contract has Product X.
Snazzy, eh? Let us know if this tip comes in handy or need a Microsoft CRM Partner to work assist in your project.
Happy CRM'ing.
i try to put into crm, but its not working for me..
I cant see it in my workflow.
any step I did wrong ??
The following is my code: after that I registered it into crm.
---------------------------------------------------------------------------------
using System;
using System.Activities;
using System.Linq;
using System.ServiceModel;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
namespace FetchWFExample
{
public class FetchWf : CodeActivity
{
protected override void Execute(CodeActivityContext executionContext)
{
var context = executionContext.GetExtension();
var serviceFatory = executionContext.GetExtension();
var service = serviceFatory.CreateOrganizationService(context.UserId);
Opportunity.Set(executionContext, false);
const string fetch = "" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
if (service.RetrieveMultiple(new FetchExpression(fetch)).Entities.Count > 0)
Opportunity.Set(executionContext, true);
}
[Output("Opportunity")]
public OutArgument Opportunity { get; set; }
}
}