Skip to main content

Notifications

Announcements

No record found.

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

  • Pavan Deepala Profile Picture
    Pavan Deepala 90 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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

  • Suggested answer
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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
    Pavan Deepala 90 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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
    gdas Profile Picture
    gdas 50,085 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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.

  • CMilton Profile Picture
    CMilton 110 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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
    gdas 50,085 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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
    CMilton 110 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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.

  • Verified answer
    Michel van den Brink Profile Picture
    Michel van den Brink 4,697 on at
    RE: Can you pass CRM parameters into a JavaScript web resource?

    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 :-)

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans