locked
Use JScript Web Resource in HTML Web Resource RRS feed

  • Question

  • I have a JScript Web Resource with a function PrintMessage(). The Jscript Resource is

    Name: new_SDK.JScriptTest
    URL: https://[org].crm.dynamics.com//WebResources/new_SDK.JScriptTest
    Code: if (typeof (SDK) == "undefined")  SDK = { __namespace: true };
             SDK.JScriptTest = {
                 PrintMessage:function(msg) { alert(msg); }
                 __namespace: true
             };

    I can call the function by adding an OnLoad handler to an entity and defining

    Library: new_SDK.JScriptTest
    Function: PrintMessage
    Argument: "Hello"

    However, I am having difficulties using the PrintMessage function in a HTML Web Resource. It always give me the following error:

    'SDK' is undefined.
    URL: https://[org].crm.dynamics.com/tools/webresourceditor/webresourceeditor.aspx?appSolutionId=....

    This error happens when a test the HTML form. When I integrate the form into an entity then nothing happens. I tried to reference the jscript in many ways without success. Here is the code of the Html Web Resource:

    <HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE></TITLE>
    <SCRIPT type=text/javascript src="new_SDK.JScriptTest.js"></SCRIPT>
    <SCRIPT type=text/javascript>
    SDK.JScriptTest.PrintMessage("ok 2");

    Why does the HTML Web Resource not see SDK?

    Btw, I saw a couple of references that names the JScript resource new_/Scripts/SDK.JScriptTest.js". I assume this will put the jscript into a subfolder Scripts but what happens with the 'new_'? Are there now two different names, a logical name 'new_/Scripts/SDK.JScript.js" and a physical name "SDK.JScript.js"? 

    Tuesday, September 13, 2011 6:20 PM

Answers

  • Performing a Retrieve call would be absolute overkill for this scenario.  hfaun, you're on the right track, but I think the pathing of your JS web resource is incorrect.  Please reference this blog article:

    http://inogic.blogspot.com/2011/03/use-of-web-resources-in-crm-2011.html

    and also the CRM SDK:

    http://msdn.microsoft.com/en-us/library/gg309473.aspx


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.
    • Marked as answer by hfaun Tuesday, September 13, 2011 8:49 PM
    Tuesday, September 13, 2011 8:10 PM
    Moderator
  • Not trying to hijack this thread. Apologize if I do...

    I think you are on the right path using relative path, which is the recommended approach by CRM SDK Document. I think the matter is to find out what URL the web resource is using in CRM. You can find out from Settings | Customizations | Customize the System. In the opened window, if you click "Web Resources" link on the left, you will see a list of web resources that are currently in the system. Depending on what resource name you are using for the SDK script, it could be something like this:

    <SCRIPT type="text/javascript" src="./new_SDK.JScriptTest.js"></SCRIPT>
    
    

    Or maybe even

    <SCRIPT type="text/javascript" src="./new_SDK.JScriptTest"></SCRIPT>
    

    PS. Just realized that Dave is 30 seconds ahead of me. I will still post the response shamelessly...


    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by hfaun Tuesday, September 13, 2011 8:49 PM
    Tuesday, September 13, 2011 8:12 PM

All replies

  • You could just embed your jscript in the html resource in  <script></script> tags. 

    Otherwise you could do a retrieve call on the webresource and decode the content (It's base 64 encoded) and then use it.

     


    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, September 13, 2011 7:09 PM
    Moderator
  • Jamie, thanks. So does that mean the approach I chose is not supported? I saw an example on the net that seems to use that approach (http://social.microsoft.com/Forums/en/crmdevelopment/thread/f501c019-aa7f-4d78-8390-5f11d1dd8820)

    I don't want to include the jscript code in the html resource. So if the above indeed does not work then can you elaborate on that other suggestion of your (retrive call on webresource and decode).

    Tuesday, September 13, 2011 7:47 PM
  • Performing a Retrieve call would be absolute overkill for this scenario.  hfaun, you're on the right track, but I think the pathing of your JS web resource is incorrect.  Please reference this blog article:

    http://inogic.blogspot.com/2011/03/use-of-web-resources-in-crm-2011.html

    and also the CRM SDK:

    http://msdn.microsoft.com/en-us/library/gg309473.aspx


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.
    • Marked as answer by hfaun Tuesday, September 13, 2011 8:49 PM
    Tuesday, September 13, 2011 8:10 PM
    Moderator
  • Not trying to hijack this thread. Apologize if I do...

    I think you are on the right path using relative path, which is the recommended approach by CRM SDK Document. I think the matter is to find out what URL the web resource is using in CRM. You can find out from Settings | Customizations | Customize the System. In the opened window, if you click "Web Resources" link on the left, you will see a list of web resources that are currently in the system. Depending on what resource name you are using for the SDK script, it could be something like this:

    <SCRIPT type="text/javascript" src="./new_SDK.JScriptTest.js"></SCRIPT>
    
    

    Or maybe even

    <SCRIPT type="text/javascript" src="./new_SDK.JScriptTest"></SCRIPT>
    

    PS. Just realized that Dave is 30 seconds ahead of me. I will still post the response shamelessly...


    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by hfaun Tuesday, September 13, 2011 8:49 PM
    Tuesday, September 13, 2011 8:12 PM
  • Daniel, David, thanks for the responses. It turns out that I had to leave out the .js. After removing .js it worked. Thanks a lot for the help.

    Tuesday, September 13, 2011 8:49 PM