1
Vote

CamlJs ToString undefined error

description

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()
                .Where()
                .LookupMultiField("Tag")
                .IncludesSuchItemThat()
                .ValueAsText()
                .In(['a', 'b', 'authorization form'])
                .ToString();
    console.log(str);
    </script>
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

comments

omlin wrote Jan 7 at 1:55 AM

Hi,

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 7: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() {
        SP.SOD.executeOrDelayUntilScriptLoaded(call_camljsfunction,'sp.js');
    });
Still getting errors in IE11 but working in Chrome.