Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

post event catch two updates

(1) ShareShare
ReportReport
Posted on by 6
I wrote a javascript to open a form on a certen condtion.
Sometimes (and depend on user)two forms open when i push a next stage button on a business flow bar.
That doesn't happen when i push a save button of the form.
I already turn on audit trail and checked it.It looks like two updates event happen ( one in a form and one in a business flow bar)
So far this happens on only my laptop.
I tried flushing all cache and history.
How can I know what's happening?
 
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 8,699 Super User 2024 Season 1 on at
    post event catch two updates
    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans