locked
crm 2011 javascript - load scripts onload in a view or dashboard? RRS feed

  • Question

  • I’ve created some new ribbon buttons that use functions that are in more than one web resource. I’ve solved this by using a script to loads them and append them to the body tag within the primary function that the ribbon buttons trigger.

    Now, the problem. The scripts/resources doesn’t load on the first click, but the second, and I would like to have the resources to be loaded in onload or the first click =)
    This is a view and/or a dashboard… Is this even possible?

    Any ideas?

    Tuesday, May 28, 2013 8:29 AM

Answers

All replies

  • You can attach a custom displayrule to any group-based item in the Ribbon xml.  That should run automatically when your grid view displays in a window.  I have never attempted to edit the dashboard ribbon, so I don't know if it's possible there.  If all else fails you could run the dashboard from within an IFrame then call your script from there.
    Tuesday, May 28, 2013 8:15 PM
  • Hi,

    Could you describe your scenario in a little more depth - I'm sure there is a way of doing what you need to.


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, May 28, 2013 8:47 PM
    Answerer
  • The following blog should cover attaching a custom action to the ribbon:

    http://myencounterwithcrm.wordpress.com/2011/05/24/walkthrough-adding-customrule-to-outofbox-ribbon-button/

    -JayB

    Tuesday, May 28, 2013 9:06 PM
  • I’ve created two new ribbon buttons that work as intended but the resources that I need are loaded within the JavaScript function that runs when the button is clicked. The function fires but the resources loads to slow or not at all on the first click, so the rest of the scripts run nonetheless and fails.
    So basically this happens:
    Click one
    - Button click
    - Resources gets loaded
    - Sub functions runs and fails
    Click two
    - Button click
    - Resources gets loaded, but are already loaded
    - Sub functions runs successfully
    Wednesday, May 29, 2013 5:51 AM
  • Hi,

    So, if I understand you correctly you are loading a second javascript webresource to the one that is referenced by the ribbon button in order that you can call a function defined within it.

    I wouldn't recommend dynamically loading the second webresource - rather define it using the technique described here - http://rajeevpentyala.wordpress.com/2012/05/23/loading-dependent-jscript-libraries-in-ribbon-buttons-execution-crm-2011/

    You add both javascript libraries to the ribbon command definition, but call isNaN on the common one simply to ensure it is loaded.

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by HalSoul Wednesday, May 29, 2013 8:59 AM
    Wednesday, May 29, 2013 7:37 AM
    Answerer
  • Works! :-D Thanks!
    Wednesday, May 29, 2013 8:59 AM