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:
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 |
Suppose you’re handling the Account entity in Dynamics 365.
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.
We query the workflow table using Web API and filter by:
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 }); } }
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.
This method is very useful when dealing with sensitive fields like Credit Limit, Risk Category, or Approval fields in Dynamics 365.
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.
The post Retrieve and Validate Field Associated Workflows in Dynamics 365/Dataverse first appeared on Microsoft Dynamics 365 CRM Tips and Tricks.
Original Post https://www.inogic.com/blog/2025/08/retrieve-and-validate-field-associated-workflows-in-dynamics-365-dataverse/