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 Pass Context as a First Parameter to a function,when the function is called from Ribbon Button Click

(0) ShareShare
ReportReport
Posted on by 2,715

Hello All,

      I want to know whether it is possible to pass " Context as a  First Parameter to a function,when the function is called from Ribbon Button Click",?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at

    Modify your js like below &Try adding your js in the form

    function callRibbonButton(executionContext) {

        var attribute = executionContext.getEventSource();

       var fieldName = attribute.getName();

        var control = Xrm.Page.getControl(fieldName);

    }

    Refer below for how to pass context as first parameter in js

    www.magnetismsolutions.com/.../dynamics_crm_2011_javascript_get_attribute_from_onchange

    Hope this helps

  • Ramakanta Profile Picture
    2,715 on at

    Hi,Context is coming as "undefined " even after adding the JS Library into Form,

    Note: i can't register the event on any field change,i want to call the function from ribbon only,is there any option to pass the context.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You would need to get the context from within the function. The ribbon button does not have a parameter for execution context.

  • Ramakanta Profile Picture
    2,715 on at

    How i will able to get?

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Inside your function you can use Xrm.Page.context to get the context.

    If that's not it, please describe what you are trying to do.

  • Ramakanta Profile Picture
    2,715 on at

    Basically i need this because i want to pass some parameters to my Action,for which i can't use the Xrm.Page as it will be Deprecated in future

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Are you already using Dynamics 365 v9?

    We have not upgraded yet to the new client side model for our solutions (mostly on D365 8.2), but this should still work on v9 as well.

    For v9, you could be using Xrm.Utility.getGlobalContext:

    docs.microsoft.com/.../getglobalcontext

    We call a lot of actions from ribbon buttons, and are using the process.js library:

    github.com/.../processjs

    Hope this helps.

  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at

    hi RK,

    I dnt think it will be removed immediately . Still you can use it to get form metadata. Please find the below article for better clarity.

    community.dynamics.com/.../new-in-v9-what-s-that-with-xrm-page-being-deprecated

    Hope this helps

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi all,

    Is there any solution for the posted question?

    Thanks 

    Regards,

    AW

  • Verified answer
    Community Member Profile Picture
    on at
    I have resolved the issue where we were not able to pass the form context through ribbon button. As Xrm.page is going to be deprecated , we can use following approach to get it done.
    Note :Pass "PrimaryControl " as command parameter and use the same parameter in the java script function as first argument.
    Use Following to get the form attribute : formContext.getFormContext().getAttribute("fullname").getValue();
    This solution has worked for me. i hope this will work for you as well.
    Regards
    Neeraj Agrawal

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