locked
[CRM 2016 online] Referencing javascript in a HTML webresource RRS feed

  • Question

  • Hello

    I'm attempting to use the XrmServiceToolkit with a HTML webresource, but I'm unable to create a proper reference. This is how the js webresource is defined - I don't have an English version, but the important part should be visible.

    Both the HTML and js webresources have the same publisher and both are published.

    According to the documentation I should do it like this:

        <script type="text/jscript" src="../scripts/XrmServiceToolkit.js"></script>

    or possibly this:

      <script type="text/jscript" src="../scripts/is_XrmServiceToolkit.js"></script>

    Neither of those two work though - when I try to call a method from the toolkit I get an error saying that "XrmServiceToolkit" is undefined. I have also tried using the direct URL to the js webresource, but that didn't work either.

    So my question is: how do I create a working reference? I need to do some creating/updating/retrieving from the webresource and the toolkit offers a very convinient way to do those things.


    • Edited by Grzegorz Zych Thursday, November 5, 2015 2:23 PM typo
    Thursday, November 5, 2015 2:22 PM

Answers

  • Hi,

    Why are you calling the Js of parent?

    parent.XrmServiceToolkit.Soap.Retrieve("appointment", _id, null);

    It should be as given below.

    XrmServiceToolkit.Soap.Retrieve("appointment", _id, null);

    Thanks!

    Kalim

    • Marked as answer by Grzegorz Zych Friday, November 13, 2015 8:36 AM
    Monday, November 9, 2015 2:30 AM

All replies

  • Hi,

    You have to follow directory structure. Your web resource is not able to find the xrmtoolkitlibrary.

    Please confirm Web Resource name and Xrmservicetoolkit name.

    Thanks!

    Thursday, November 5, 2015 2:54 PM
  • Thank you for the reply.

    How can I do that? All info I got is what's shown on the web resource pages: HTML, Toolkit. Does CRM have another way to peek into the directory? This is Online, so I can't just go into the file system and check for myself.

    What I understand from the documentation I linked before the structure should be something like this (considering the prefix for my publisher is IS_):

    /is_/scripts/XrmServiceToolkit.js
    /is_/???/Ankieta.html

    Therefore "../scripts/XrmServiceToolkit.js" should get me the script.

    Still, the documentation is for CRM 2015 so I undestand that things might have changed, but I can't find any official documents for 2016 yet.

    Friday, November 6, 2015 8:36 AM
  • try below.

     <script type="text/jscript" src="is_XrmServiceToolkit"></script>

    • Proposed as answer by Kalim Khan Friday, November 6, 2015 8:04 PM
    Friday, November 6, 2015 8:04 PM
  • Sadly, still no joy. This is beginning to look suspiciously like I'm missing something obvious. Just in case: here's the entire HTML file:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/jscript" src="is_XrmServiceToolkit"></script>
        <script type="text/javascript">
            function TEST()
            {
                var _id = GetCurrentId();
                alert(_id);
    
                try
                {
                    var _r = parent.XrmServiceToolkit.Soap.Retrieve("appointment", _id, null);
                    alert(JSON.stringify(_r));
                }
                catch (err)
                {
                    alert(err.message);
                }
            }
    
            function GetCurrentId()
            {
                var _val = '';
                try
                {
                    _val = parent.Xrm.Page.data.entity.getId();
                }
                catch (err)
                {
                    alert(err.message);
                }
    
                return _val;
            }
        </script>
    </head>
    <body>
        <div id="AnkietaDIV"></div>
    
        <script>
            window.onload = TEST;
        </script>
    </body>
    </html>
    "alert(_id)" returns a valid guid and the whole thing fails on the retrieve, saying that "SOAP" cannot be found in an undefined object.


    • Edited by Grzegorz Zych Saturday, November 7, 2015 10:39 PM typos
    Saturday, November 7, 2015 10:39 PM
  • you need to check how you loaded the XrmServiceToolkit as JS WebResource inside CRM and after build the relative path.

    if both are at the same level the code should be

    <script type="text/jscript" src="PREFIX_XRMSERVICETOOLKITNAMEFILE.JS"></script>

    of course you need to change PREFIX and XRMSERVICETOOLKITNAMEFILE.JS to the correct one

    if they are not at the same level (in case you created a relative path to hold the js files, something like PREFIX_/JS/WEBRESOURCES.JS

    the code should be

    <script type="text/jscript" src="PREFIX_/JS/XRMSERVICETOOLKITNAMEFILE.JS"></script>
    EDIT: didn't see your screenshot before, you need to post also the screenshot of the HTML file, so we can build the correct path


    My blog: www.crmanswers.net - CRM Theme Generator


    Sunday, November 8, 2015 1:37 AM
  • Hi,

    Why are you calling the Js of parent?

    parent.XrmServiceToolkit.Soap.Retrieve("appointment", _id, null);

    It should be as given below.

    XrmServiceToolkit.Soap.Retrieve("appointment", _id, null);

    Thanks!

    Kalim

    • Marked as answer by Grzegorz Zych Friday, November 13, 2015 8:36 AM
    Monday, November 9, 2015 2:30 AM
  • I have the JS file added to the main form and I was hoping I could call that instead and I forgot to remove the "parent" after that. After removing it the reference works, so that's that :)

    Thank you both for your help.

    Friday, November 13, 2015 8:35 AM