Chon,
To execute workflow for more records, you can use SDK, you can refer to this snippet.
*You would need to create a ExecuteWorkflowRequest message
Example:
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
{
WorkflowId = _workflowId,
EntityId = _leadId
};
Source:
msdn.microsoft.com/.../gg309600.aspx
msdn.microsoft.com/.../microsoft.crm.sdk.messages.executeworkflowrequest.aspx
My suggestion:
Put this code:
// Create an ExecuteWorkflow request.
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
{
WorkflowId = _workflowId,
EntityId = _leadId
};
// Execute the workflow.
ExecuteWorkflowResponse response =
(ExecuteWorkflowResponse)_serviceProxy.Execute(request);
Under your looping, for or foreach.
Make this as dynamically...
_leadId
This is will be your requested entity record id that you want to execute against it.
First of all, you need to retrieve all the records, for example retrieve all lead, using QueryExpression or using fetchxml.
Then using Retrieve Multiple request.
See this:
msdn.microsoft.com/.../microsoft.xrm.sdk.iorganizationservice.retrievemultiple.aspx
For example:
// Retrieve the related opportunity products
QueryExpression recordQuery = new QueryExpression
{
EntityName = Lead.EntityLogicalName,
ColumnSet = new ColumnSet("leadid", "name"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "statuscode", //for example only active Lead
Operator = ConditionOperator.Equal,
Values = { "Active" } //or SomeEnum.Active.ToString() if you want use good practice // or can be int 0
}
}
}
};
DataCollection<Entity> records = _serviceProxy.RetrieveMultiple(
recordQuery).Entities;
foreach (Entity entity in records)
{
Lead lead = (Lead)entity;
Console.WriteLine("Retrieved Lead{0}",
opportunityProduct.Name.ToString());
_leadId = lead.LeadId;
// Create an ExecuteWorkflow request.
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
{
WorkflowId = _workflowId,
EntityId = _leadId
};
// Execute the workflow.
ExecuteWorkflowResponse response =
(ExecuteWorkflowResponse)_serviceProxy.Execute(request);
}
//or you can use late bound
Sorry if there are some typo since I type in directly in this editor, not using C# editor :)
Just to give the concept there, not a real exact code.
Hope this helps.
Thanks.