Using in CRM web resource

May 29, 2013 at 3:12 PM
Hi there!

I've been using this on CRM forms to lovely effect, although I'm having trouble using in a html web resource in CRM - I get Unable to get property 'createRecord' of undefined or null reference or similar when trying to call functions.

I've included the normal JS libraries that I normally do on CRM forms...am I missing something silly here?

Pete
Coordinator
May 29, 2013 at 3:56 PM
I suspect this is a reference path issue. You can try to use Fiddler to check if you are getting 404 error for the referenced library.

The following blog post might help in terms of understanding the path of CRM web resources.
http://www.develop1.net/public/post/CRM-Developer-e28098Must-Knowe28099-2-Web-Resource-Caching.aspx

Hope this helps.
Daniel Cai
May 29, 2013 at 4:09 PM
Cheers Daniel will check this out. It's not within an iFrame i'm trying to do this by the way, i'm planning on having a completely stand-alone html page, I don't know if that makes a difference...?

Pete
Coordinator
May 29, 2013 at 4:12 PM
Edited May 29, 2013 at 4:14 PM
Stand-alone HTML page is fine as long as it is hosted as web resources. When you use stand-alone HTML page, you need to also add ClientGlobalContext.js.aspx as a script file to your HTML head.
May 29, 2013 at 4:58 PM
Edited May 30, 2013 at 9:42 AM
I've got that in there - this is what i've got so far, am I missing something obvious?
<HTML>
<HEAD>
    <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
    <SCRIPT src="ksw_XrmSvcToolkit.js" type="text/javascript"></SCRIPT>
    <SCRIPT src="ksw_json2.js" type="text/javascript"></SCRIPT>
    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>

    <SCRIPT language="javascript">      
        function test()
        {
            XrmSvcToolkit.createRecord
            ({
                entityName: "Account",
                entity: {Name: "Test"},
                async: false,
                successCallback: function (result) 
                {
                    alert("Huzzah!");
                },
                errorCallback: function (error) 
                {
                    alert("There was an error when creating the order record");
                    alert(error.description);
                }
            });
        }
    </SCRIPT>
</HEAD>
<BODY>  
    <INPUT type="button" value="Test" onclick="test()" />
</BODY>
</HTML>
Coordinator
May 29, 2013 at 5:44 PM
Pete, web resources won't be under the same folder (virtual one), so you would need to prepend the path in order to reference the script files properly. You can find each web resource's path by opening it in CRM, then you can use either relative path or absolute path in your HTML web resource file.
May 30, 2013 at 9:41 AM
Hi Daniel,

Firstly, thanks for your on-going help with this.

I've got all my xrmsvctoolkit web resources and html in the same folder, and I think it's finding these - if I change the reference to anything else it doesn't find XrmSvcToolkit at all:

SCRIPT5009: 'XrmSvcToolkit' is undefined

Whereas it's the following error I seem to be getting when I've got everything referenced:

SCRIPT5007: Unable to get property 'createRecord' of undefined or null reference

Is it ClientGlobalContext i'm not referencing properly? I can navigate to the URL using the relative path referenced here, so it appears to be in the right place....
Also, apologies for plain text code above, i'll edit this now as it's not helping matters!

Pete
May 30, 2013 at 10:20 AM
I've just tried this in another environment which I've got set up in Outlook and got

'Xrm' is undefined in XrmSvcToolkit.js, could this be related?
Coordinator
May 30, 2013 at 9:12 PM

Hey, just a wild shot, try swapping json2 and XrmSvcToolkit loading lines. This aside, I’d say something’s gone terribly wrong and your XrmSvcToolkit source is corrupted.