Home

Dec 8, 2011

CRM 2011 : Javascript giving error randomly. CRMEncodeDecode is undefined

 

I was executing fetchXml using JavaScript (for more details on how to execute fetchxml using JS refer here) in my Html+JS application.

One of the line of code was - request += CrmEncodeDecode.CrmXmlEncode(sFetchXml);
I was getting rando error “CrmEncodeDecode is undefined” . CrmEncodeDecode object is a part of global.ashx which was not loading properly. As it was a test app, I was using hard-coded CRMurl and not using “GetGlobalContext().getServerUrl();” to get it. 
If you use GetGlobalContext(), it also loads related files as well. For getting CRM config data, I would recommend  to use client global context by adding below line of code in your application.
<script src="../../WebResources/ClientGlobalContext.js.aspx"></script>


Happy JS,

2 comments:

Gary said...

I added the reference as you suggested with

src="http://crmServer/WebResources/ClientGlobalContext.js.aspx"

But I am still getting the same error as you were getting. Any ideas what else I can try?

Thanks!

prasadreddy27 said...

Thanks a lot...It is working for me.