Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Pass JavaScript Execution Context

Posted on by

Hi guys,

i have 2 functions in same webresource and i pass the Execution Context in function 1 and do some actions and i call the function 2 from function 1 and am also pass the Execution Context in function 2..but execution context preventdefault is not working..

my Javascript like..

function preventAutoSave(executionContext)

{

var eventArgs = executionContext.getEventArgs();

if (eventArgs.getSaveMode() == 70)

{

eventArgs.preventDefault();

}else{

compare(eventArgs);

}

}

function compare(eventArgs)

{

..............

...............

.................

if(eventArgs.getSaveMode() == 1){

eventArgs.preventDefault();

}

}

i wrote i like this but record is save..i want to dont save the record and i want to know how to pass executionContext from one function to another

*This post is locked for comments

  • Verified answer
    DineshRaja Profile Picture
    DineshRaja on at
    RE: Pass JavaScript Execution Context

    Thank You Guys..Actually am call the prevent default inside the REST API in asynchronous thats why the prevent default is not work..after change the REST API to synchronous prevent default is works..

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Pass JavaScript Execution Context

    Hi Dinesh ,

    I tried your code , its working fine . Only you need to handle " Save and Close  " and "Save and New ". Make sure you are calling the method in onsave and passing execution context from event handler.

    function preventAutoSave(executionContext) {   
        var eventArgs = executionContext.getEventArgs();
        if (eventArgs.getSaveMode() == 70 ) {
            eventArgs.preventDefault();
        } else {
            compare(eventArgs);
        }
    }
    
    function compare(eventArgs) {
        if (eventArgs.getSaveMode() == 1 || eventArgs.getSaveMode() == 2 || eventArgs.getSaveMode() == 59) {  // 59 = Save and New , 2 = Save and Close
            eventArgs.preventDefault();
        }
    }

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Pass JavaScript Execution Context

    Hi Dinesh,

    This should work. did  you try to debug the code and see what exactly is the error and on what line. on what form event you are calling the function?

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans