/// <summary>
/// Outputs the first active flow
/// </summary>
/// <param name="service">Authenticated client implementing the IOrganizationService interface</param>
public static void OutputFirstActiveFlow(IOrganizationService service)
{
var query = new QueryExpression("workflow")
{
ColumnSet = new ColumnSet("category",
"createdby",
"createdon",
"description",
"ismanaged",
"modifiedby",
"modifiedon",
"name",
"ownerid",
"statecode",
"type",
"workflowid",
"workflowidunique"),
Criteria = new FilterExpression(LogicalOperator.And)
{
Conditions = {
{ new ConditionExpression(
"category",
ConditionOperator.Equal,
5) }, // Cloud Flow
{ new ConditionExpression(
"statecode",
ConditionOperator.Equal,
1) } // Active
}
},
TopCount = 1 // Limit to one record
};
EntityCollection workflows = service.RetrieveMultiple(query);
Entity workflow = workflows.Entities.FirstOrDefault();
Console.WriteLine($"category: {workflow.FormattedValues["category"]}");
Console.WriteLine($"createdby: {workflow.FormattedValues["createdby"]}");
Console.WriteLine($"createdon: {workflow.FormattedValues["createdon"]}");
// Description may be null
Console.WriteLine($"description: {workflow.GetAttributeValue<string>("description")}");
Console.WriteLine($"ismanaged: {workflow.FormattedValues["ismanaged"]}");
Console.WriteLine($"modifiedby: {workflow.FormattedValues["modifiedby"]}");
Console.WriteLine($"modifiedon: {workflow.FormattedValues["modifiedon"]}");
Console.WriteLine($"name: {workflow["name"]}");
Console.WriteLine($"ownerid: {workflow.FormattedValues["ownerid"]}");
Console.WriteLine($"statecode: {workflow.FormattedValues["statecode"]}");
Console.WriteLine($"type: {workflow.FormattedValues["type"]}");
Console.WriteLine($"workflowid: {workflow["workflowid"]}");
Console.WriteLine($"workflowidunique: {workflow["workflowidunique"]}");
}