private void buttonLoadWorkflows_Click(object sender, EventArgs e) { try { if (comboBoxConnectionSource.SelectedItem == null) { MessageBox.Show("You must select a connection before loading workflows!"); return; } toolStripStatusLabel1.Text = "Loading workflows. Please wait..."; Application.DoEvents(); string fetchXMLQuery = @" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='workflow'><attribute name='workflowid' /><attribute name='name' /> <order attribute='name' descending='false' /><filter type='and'> <condition attribute='type' operator='eq' value='1' /> <condition attribute='category' operator='eq' value='0' /> <condition attribute='statecode' operator='eq' value='1' /> <condition attribute='ondemand' operator='eq' value='1' /> </filter></entity></fetch>"; MSCRMConnection connection = cm.MSCRMConnections[comboBoxConnectionSource.SelectedIndex]; man._serviceProxy = cm.connect(connection); EntityCollection result = man._serviceProxy.RetrieveMultiple(new FetchExpression(fetchXMLQuery)); List <MSCRMWorkflow> workflows = new List <MSCRMWorkflow>(); foreach (var workflow in result.Entities) { //this.comboBoxWorkflows.Items.AddRange(new object[] { (string)workflow["name"] }); workflows.Add(new MSCRMWorkflow { Id = (Guid)workflow["workflowid"], Name = (string)workflow["name"] }); } man.WriteWorkflows(comboBoxConnectionSource.SelectedItem.ToString(), workflows); //Read workflows this.comboBoxWorkflows.Items.Clear(); List <MSCRMWorkflow> readedWorkflows = man.ReadWorkflows(comboBoxConnectionSource.SelectedItem.ToString()); foreach (MSCRMWorkflow workflow in readedWorkflows) { this.comboBoxWorkflows.Items.AddRange(new object[] { workflow.Name }); } this.Workflows = readedWorkflows; toolStripStatusLabel1.Text = "Workflows loaded."; } catch (Exception ex) { if (ex.InnerException != null) { MessageBox.Show("Error:" + ex.Message + "\n" + ex.InnerException.Message); toolStripStatusLabel1.Text = "Error."; } else { MessageBox.Show("Error:" + ex.Message); toolStripStatusLabel1.Text = "Error."; } } }