Workflows (also known as processes) in Dynamics 365 automate business logic such as approvals, field updates, or triggering other workflow actions. Sometimes, we need to check whether a workflow exists for a specific field before performing an action on a form.
For example, when updating sensitive fields like Credit Limit or Risk Category, you may want to warn users if workflows are already associated with these fields, since saving the record could trigger important automated processes.
In this blog, we’ll explore:
- Workflow categories and what they mean.
- How to retrieve workflows related to a specific field.
- A practical implementation where we check workflows before setting a Risk Category
Workflow Categories in Dynamics 365
In Dynamics 365, every workflow or process is assigned a Category value in the workflow table. For detailed insights into workflow properties, you can always check Microsoft’s official documentation for the latest updates. Below are the key category values:
Category Value | Workflow Type |
0 | Classic Workflow |
1 | Dialog |
2 | Business Rule |
3 | Action |
4 | Business Process Flow (BPF) |
5 | Modern Flow (Cloud Flow) |
6 | Desktop Flow |
7 | AI Flow |
Use Case
Suppose you’re handling the Account entity in Dynamics 365.
- When a user updates the Credit Limit, the system automatically sets the Risk Category (High, Medium, or Low).
- But before setting this field, we want to check if any workflows (category = 5, i.e., Cloud Flows) are already linked with this Risk Category field.
- If workflows exist, we show a confirmation pop-up to the user:
“There are workflows associated with this field. Saving may trigger them. Do you want to continue?”
This ensures users are aware of possible automated actions before proceeding.
Implementation in Power Apps (JavaScript on Form)
We’ll add a JavaScript function to the onChange event of the Credit Limit field.
Step 1: Retrieve Workflows from Dataverse
We query the workflow table using Web API and filter by:
- Category = 5 (Cloud Flow)
- clientdata containing our field (in this case, cre44_riskcategory)
Code:
// Helper function to check if workflows exist for a given field async function checkAssociatedWorkflows(fieldLogicalName) { try { const query = "?$select=workflowid,name,clientdata" + "&$filter=category eq 5 and contains(clientdata, '" + fieldLogicalName.toLowerCase() + "')"; const results = await Xrm.WebApi.retrieveMultipleRecords("workflow", query); return results.entities && results.entities.length > 0; } catch (error) { console.error("Error fetching workflows:", error.message); return false; // fail safe → act like no workflows } }
Step 2: Handle Credit Limit Change
When the Credit Limit changes, we determine the Risk Category value and then check workflows.
Code:
// Function: Called on Credit Limit field OnChange async function onCreditLimitChange(executionContext) { try { var formContext = executionContext.getFormContext(); var creditLimit = formContext.getAttribute("creditlimit").getValue(); if (creditLimit == null) return; // Auto-set Risk Category based on Credit Limit let riskCategoryValue = null; // OptionSet Values: 1=High, 2=Medium, 3=Low (example) if (creditLimit > 100000) { riskCategoryValue = 1; // High } else if (creditLimit > 50000) { riskCategoryValue = 2; // Medium } else { riskCategoryValue = 3; // Low } // Before setting High/Medium, check workflows if (riskCategoryValue === 1 || riskCategoryValue === 2) { const hasWorkflows = await checkAssociatedWorkflows("cre44_riskcategory"); if (hasWorkflows) { Xrm.Navigation.openConfirmDialog( { title: "Workflows Detected", text: "There are workflows associated with Risk Category. Setting it to High/Medium may trigger them. Do you want to continue?", confirmButtonLabel: "Yes, Continue", cancelButtonLabel: "No, Cancel" } ).then(function (result) { if (result.confirmed) { // User confirmed → set field formContext.getAttribute("cre44_riskcategory").setValue(riskCategoryValue); } else { // User cancelled → reset field formContext.getAttribute("cre44_riskcategory").setValue(null); } }); } else { // No workflows → set directly formContext.getAttribute("cre44_riskcategory").setValue(riskCategoryValue); } } else { // Low risk → set directly formContext.getAttribute("cre44_riskcategory").setValue(riskCategoryValue); } } catch (error) { Xrm.Navigation.openAlertDialog({ title: "Error", text: "A failure occurred in Web API.\nDetails: " + error.message }); } }
Execution in Account Form
1. Add the provided JavaScript web resource within your Dynamics 365 solution.
2. On the Account form, bind the onCreditLimitChange function to the Credit Limit field’s OnChange event.
3. Publish and test:
If workflows exist for Risk Category (and it’s set to High/Medium), you’ll get a confirmation popup, and if no workflows exist, the field is updated directly.
Summary
- Workflows in Dynamics 365 are categorized by type (Classic, Dialog, Action, BPF, Cloud Flow).
- Retrieve workflows from the workflow table by executing Web API queries.
- In our example, we checked for Cloud Flows (category 5) linked to the Risk Category field before updating it.
- This approach adds a safety layer, ensuring users are aware of automation that might get triggered.
This method is very useful when dealing with sensitive fields like Credit Limit, Risk Category, or Approval fields in Dynamics 365.
Conclusion
Identifying workflows linked to specific fields in Dynamics 365 helps avoid unexpected automation. It ensures better control while updating sensitive fields like Credit Limit or Risk Category. This improves system reliability and reduces troubleshooting efforts. Overall, it empowers admins to manage workflows with confidence.