The behavior you're experiencing—where two forms open simultaneously under certain conditions—indicates that multiple events might be triggering the JavaScript logic. Since this happens inconsistently and primarily on your laptop, here are steps to debug and address the issue:
Steps to Investigate the Issue
1. Check Your JavaScript Code
Double-check the trigger points:
Ensure the JavaScript logic is not being called both by the Business Process Flow (BPF) button and some other event (e.g., onSave or onLoad).
Look for duplicate event handlers:
Ensure the function is registered only once. Use removeOnChange for clean-up if needed before re-adding the event.
Example:
function myFunction(executionContext) {
// Prevent redundant execution
if (executionContext.getDepth() > 1) {
return; // Exit if triggered multiple times
}
// Your form logic here
}
2. Debug the Execution Context
Add logging to your JavaScript code to track when and how the function is executed.
console.log("Function triggered at: " + new Date().toISOString());
console.log("Execution Context Depth: " + executionContext.getDepth());
Use executionContext.getDepth() to determine if the function is being called more than once for the same event.
3. Audit Event Logs in Dynamics
Audit trails show what triggered the updates:
Look for "Source" fields in the audit logs to distinguish whether the updates are from:
A user action (e.g., BPF button click).
A plugin or workflow.
JavaScript logic.
If multiple updates are logged, note the order and timing.
4. Test on Another Machine
Since the issue occurs only on your laptop:
Test the same scenario on another user's machine or browser to rule out local browser issues or machine-specific settings.
5. Check Browser Developer Tools
Use the Network Tab in browser developer tools:
1. Open the developer tools in your browser (e.g., Chrome/Edge: F12).
2. Recreate the issue.
3. Check for duplicate calls to Dynamics APIs or forms.
Use the Console Tab:
Check for JavaScript errors or multiple triggers logged by your debug statements.
6. Inspect Business Process Flow Events
The Next Stage button in a BPF triggers an onSave event by default.
Ensure your JavaScript logic does not execute during the onSave unless explicitly required.
Add conditional checks to differentiate between onSave triggered by the BPF and the form.
Example:
function onSave(executionContext) {
var saveMode = executionContext.getEventArgs().getSaveMode();
if (saveMode === 70) { // Save triggered by BPF
console.log("Save triggered by Business Process Flow.");
return;
}
// Regular form save logic here
}
7. Disable Other Scripts or Customizations
Temporarily disable other scripts or plugins related to the form or BPF to isolate the issue.
Check for overlapping logic in workflows, plugins, or Power Automate flows that might also update the record.
Potential Fixes
1. Avoid Overlapping Event Handlers:
Ensure form scripts are not unnecessarily bound to both onSave and BPF Next Stage.
3. Browser Reset:
Clear the browser cache/cookies again and try in a private/incognito window.
If the issue persists, consider reinstalling or updating your browser.
4. Environment-Specific Debugging:
Check if the issue occurs in all environments (e.g., dev, test, prod).
Use Fiddler or similar tools to monitor network calls for duplicates.
Conclusion
By using debug logs, event depth checks, and isolating triggers, you can identify whether the issue stems from redundant triggers or environmental factors. If the problem persists after these steps, consider disabling other customizations temporarily or testing on a clean Dynamics 365 instance.