Integrate external CamlBuilder

We try to use an external CAML Builder tool from Andrei Markeev https://github.com/andrei-markeev/camljs to build complex CAMLs, but we've got always errors to add the external script file. Does anyone has use this CAML tool already? Some example code for integration?

Okay, found the solution:

window.$ = $;
window.jQuery = jQuery;
 
fd.spRendered(function() {   

    // To avoid conflicts with requireJS which is available by default in SharePoint
    // we unset 'define' function until the script are loaded 
    var define = window.define;
    window.define = undefined;
    
    $.getScript('/sites/produktkonfigurator/SiteAssets/camljs.js')
    .then(function() {
    
        // we unset 'define' function until the script are loaded -> set back
        window.define = define;
    
        var camlBuilder = new CamlBuilder();
        var caml = camlBuilder.Where()
            .TextField("Email").EqualTo("support@google.com")
            .Or()
            .TextField("Email").EqualTo("plus@google.com")
            .Or()
            .TextField("Title").BeginsWith("[Google]")
            .Or()
            .TextField("Content").Contains("Google")
            .ToString();

        console.log(caml);

    });
});
1 Like