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)

Can you pass CRM parameters into a JavaScript web resource?

(0) ShareShare
ReportReport
Posted on by 110

When creating a ribbon button, you can pass CRM parameters to it, such as SelectedControlSelectedItemsIds and SelectedControlSelectedItemReferences.

Can you pass these into a custom JavaScript web resource and use them in functions?


Thanks,
Chris

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at

    Hello Chris,

    Yes indeed, you can pass those.

    When adding a custom JavaScript function as command action, the CRM parameters you add will be passed to that function, in the order you added them.

    Let's say you selected SelectedControlSelectedItemsIds as the first parameter, that would mean it would get passed like this:

    function MyRibbonButtonFunction(selectedControlSelectedItemsIds) {
    
     for(var i = 0; i < selectedControlSelectedItemsIds.length; i++) {
    
        // Do something
    
     }
    
    }

    Take a look at the documentation for passing ribbon parameters to functions - it the reference for all possible parameters some examples too:
    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/customize-dev/pass-dynamics-365-data-page-parameter-ribbon-actions 

    Hope this answers your question :-)

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

    Hi Chris,

    Yes you can see how to get selected item from grid-

    ribbonworkbench.uservoice.com/.../129783-pass-the-currently-selected-grid-row-s-to-a-custo

    Once you get the I'd you can easily get all the columns using web api retrieve method.

    Now to pass parameter in web resource you need to follow below reference.

    community.dynamics.com/.../pass-parameters-to-html-web-resource

    Hope this helps.

  • CMilton Profile Picture
    110 on at

    Thanks for the response Michel,

    I can see that my question was a bit misleading.

    I am looking to pass the CRM functions to an event handler on a form, and then have the code run onChange of a field, like below:

    2018_2D00_11_2D00_01-16_5F00_47_5F00_02_2D00_Window.png

    My code would then be something like this

    function logEntityName(PrimaryEntityTypeName) {
        console.log(PrimaryEntityTypeName);
    }


    I hope this makes sense, it is possible?

    Thanks,

    Chris

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

    Hi Chris,

    You can pass there any valid javascript statement - call to function etc..

    For example -

    To pass entity name you can put below  script-

    Xrm.Page.data.entity.getEntityName()  

    To pass current record name value as argument you can put below script-

    Xrm.Page.getAttribute('name').getValue()

    CRM takes whatever you type in the parameters field and puts as parameter to function call.

    function logEntityName(param1) {

       console.log(param1);

    }

  • CMilton Profile Picture
    110 on at

    Thanks for the reply Goutam,

    That was just an brief example to give an idea of what I am trying to achieve, my actual code is more complex and requires more parameters.

    Do you know CRM parameters such as commandProperties and PrimaryEntityTypeName are only available with ribbon actions?

    Thanks,
    Chris

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

    Hi Chris ,

    I don't think you can pass such type of parameter before use any parameter you should check whether this is valid variable or statement by executing in a function or using log.

    Lets take another example in your form you load one JavaScript web resource and define a variable as global  or function let say -

    var  PrimaryEntityTypeName = "contact";

    function onchangesomething()

    {

    }

    Now above variable and function name you can pass as a parameter.

  • Pavan Deepala Profile Picture
    90 on at

    Hi Goutham,

    Now that "Xrm.Page" is going to be deprecated what should be done in this scenario. Let us know if you have any solution.

    Thanks in advance.

  • Suggested answer
    NILANKA SEKHAR PAUL Profile Picture
    340 on at

    HI Pavan,

    Now Xrm.Page is deprecated. Now you should use "FormContext" instead of "Xrm.Page".

    Suppose to pass entity name you can put below script:

    function ABC(executionContext) {

    var formContext = executionContext.getFormContext();

    var getEntityName= formContext.data.entity.getEntityName();

    }

    Thank You,

    Nilanka

  • Pavan Deepala Profile Picture
    90 on at

    Hi Nilanka,

    I think you have got my question wrong.The scenario i was asking is passing entityname/any information as additional parameters to the function.

    Like

    function abc (executioncontext,entity name){

    }

    Pass Xrm.Page.data.entity.getEntityName() as secondary parameter

    Regards

    Pavan

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