Sharing a sample code through which we can Enable / Disable (turn on / turn off) multiple cloud flows using code.
E.g. here we want to turn on the below Cloud Flows owned by a specific user.
![A screenshot of a computer
Description automatically generated](https://nishantrana.me/wp-content/uploads/2024/04/a20screenshot20of20a20computer0a0adescription20automatically20generated-49.png)
Table name – Workflow and Category – Modern Flow.
![](https://nishantrana.me/wp-content/uploads/2024/04/null-18.png)
Below is the sample code, code is straightforward, we are updating the status of the record.
const string connectionString = "AuthType = ClientSecret; " +
"Url = https://[org].crm.dynamics.com/;" +
"ClientId=[GUID];" +
"ClientSecret=[Secret]";
var myServiceClient = new CrmServiceClient(connectionString);
if (myServiceClient.IsReady)
{
var query = new QueryExpression("workflow");
query.ColumnSet.AddColumns("workflowid", "name", "ownerid", "statecode", "category", "primaryentity", "solutionid");
// Category = 5 (Modern Flow)
query.Criteria.AddCondition("category", ConditionOperator.Equal, 5);
// owned by a specific user
query.Criteria.AddCondition("ownerid", ConditionOperator.Equal, "23d670c5-d02d-ee11-bdf4-0022482db7da");
var cloudFlows = myServiceClient.RetrieveMultiple(query);
foreach(var flow in cloudFlows.Entities)
{
var myFlow = new Entity("workflow", flow.Id);
// statecode = 1 (Turn On) and statecode = 0 (Turn Off)
myFlow.Attributes["statecode"] = new OptionSetValue(1);
myServiceClient.Update(myFlow);
}
}
The result :
![A screenshot of a computer
Description automatically generated](https://nishantrana.me/wp-content/uploads/2024/04/a20screenshot20of20a20computer0a0adescription20automatically20generated-50.png)
Check Work with cloud flows using code.
Hope it helps..
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts to your email.
Nice informative post. Thank you Nishant for sharing
LikeLiked by 1 person