This project is read-only.

CamlJs ToString undefined error


I am running a simple CamlJs, it works from Chrome Console and from the Chrome Extension. However when I try from a Content Editor Webpart (Sharepoint Online / O365) it gives me an error.
    <script src="/sites/intranet/Style%20Library/CI/scripts/document_library/camljs.js"></script>
    <script type="text/javascript">       
     var str = new CamlBuilder()
                .In(['a', 'b', 'authorization form'])
This is the error:
    camljs.js:948 Uncaught TypeError: Cannot read property 'create' of undefined
        at Builder.Finalize (camljs.js:948)
        at QueryToken.ToString (camljs.js:304)
        at doclib.aspx:1123


omlin wrote Jan 7 at 2:55 AM


The issue most likely happens because SP.StringBuilder that camljs uses has not yet loaded by the time when your inline script executes.
You can try the following in order to fix it:
  • wrap your code into SP.SOD.executeFunc. if I remember correctly, you need to wait for init.js
  • wrap your code into _spBodyOnLoadFunctions.push(function() { ... }) or $(document).ready
  • check if you're using the latest version of camljs library - starting from 2.5 CamlJs should be able to run without dependencies

dinnouti wrote Jan 25 at 8:50 PM

Hi, I am using Release 2.7 and still getting the error, this is how I am wrapping the call to camljs
    jQuery(document).ready(function() {
Still getting errors in IE11 but working in Chrome.