web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Pass JavaScript Execution Context

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    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?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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();
        }
    }

  • Verified answer
    DineshRaja Profile Picture
    on at

    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..

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans