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)

How to use/get context - (js) in dynamics-crm

(0) ShareShare
ReportReport
Posted on by 645

My goal is to use preventDefault event, to use it I need to use context but I don't understand the way to use it. How to get the context... I get it as undefined, obviously  I'm missing something msdn shows example : 

ExecutionContextObj.getContext()

But I'm not sure how to get- ExecutionContextObj.. How to use it ?
 

*This post is locked for comments

I have the same question (0)
  • gdas Profile Picture
    50,091 Moderator on at

    Hi,

    You can create one js method and call it in onsave.

    Here is the reference how to pass context , please have a look.

    practical-crm.blogspot.in/.../passing-execution-context-to-onchange.html

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    You need to call the preventDefault() from the context.

    Refer this:

    neilparkhurst.com/.../javascript-prevent-save

    Hope this helps.

  • sahara Profile Picture
    645 on at

    Hey Goutam,

    I read your article, according to the article It look like I need to mark 'pass execution context as first parameter' but I don't understand where..

  • Community Member Profile Picture
    on at

    Open Form. Click on Form Properties. Select On Save Event and click on "Pass execution parameter as first parameter"

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

    Hi ,

    You just go to form properties and add your web resource, select onsave and click on Add function, you can see the options to pass execution context.

  • sahara Profile Picture
    645 on at

    Hey Goutam I did it I changed my properties and at the onsave event but when I load my form I get context is undefined

    ReferenceError: 'context' is undefined, at OnLoad .... Should I change something in the OnLoad event ?

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Refresh the Foem. It happens...sometimes crm loads the previous script from cacge.

    You can also try incognito mode and check.

    Hope this helps

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

    Hi .

    Make sure you have published your web resource and forms and re validate your function that you are getting context like below function  . Its expected behavior and its should be work

    excontext2.png

    function OnSave(context) {
        var saveEvent = context.getEventArgs();
        saveEvent.preventDefault();
    
    }


  • sahara Profile Picture
    645 on at

    I reopened the page and refreshed it but the OnLoad exception still there:

    this is my context code : it looks like context in OnLoad is a must..do I need another fix?

    function OnSave(context) {      

       }

    function OnLoad(){

      isUserCanUseForm(context);

    }

    isUserCanUseForm(context){

              var saveEvent = context.getEventArgs();                    

     saveEvent.preventDefault();

     Xrm.Page.ui.close();    

    }

  • Verified answer
    Community Member Profile Picture
    on at

    function OnSave(context) {      

       isUserCanUseForm(context);

      }

    function OnLoad(){

    }

    isUserCanUseForm(context){

             var saveEvent = context.getEventArgs();                  

    saveEvent.preventDefault();

    Xrm.Page.ui.close();  

    }

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