0

I am attempting to create a filtered list view in a Calendar. It is creating everything as appropriate, but not creating the filters. It believe it's my CAML. My goal is to filter by a choice column named "Approval Status" with a value of "Approved":

    function createCalendarView() {

        var currentcontext = new SP.ClientContext.get_current();
        var hostcontext = new SP.AppContextSite(currentcontext, hostweburl);
        var context = SP.ClientContext.get_current();           
        var hostweb = hostcontext.get_web();
        var listCollection = hostweb.get_lists();
        var list = listCollection.getByTitle('Calendar');

        // Create Approved PTO View
        //get the view collection to add the view
        var viewcollection = list.get_views();
        //create a viewinfo with the view properties
        var viewInfo = new SP.ViewCreationInformation(); //create multiple views
        viewInfo.set_title("MYVIEW"); //set the title
        viewInfo.set_viewTypeKind(524288);
        viewInfo.set_setAsDefaultView(true); //set the view to default
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><Where><Eq><FieldRef Name="Approval Status"/><Value Type="Text">Approved</Value></Eq></Where></View>');
        viewInfo.set_query(camlQuery);
        //add the view to the view collection
        viewcollection.add(viewInfo);


        //load the view collection
        context.load(viewcollection);
        context.executeQueryAsync(onCalendarViewCreationSuccess, onCalendarViewCreationFail);
    }

2 Answers 2

1

This was answered at JSOM: Create Filtered Calendar View

Using the format of worked. There is no Query in the Caml:

camlQuery.set_viewXml("<Where><Eq><FieldRef Name='Approval_x0020_Status' /><Value Type='Choice'>Approved</Value></Eq></Where>");
0

Try this

camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Approval Status\'/><Value Type=\'Text\'>Approved</Value></Eq></Where></Query></View>');
4
  • No such luck. It is still creating the view without the filter applied. Does it matter that its a Calendar?
    – Kode
    Apr 8, 2015 at 19:08
  • test the query using CAML query builder and check it returns proper data. Also try to create a view using SharePoint UI and see if filter is working. Apr 8, 2015 at 19:12
  • It appears to be tied to the Calendar, as it asks for the "Calendar Columns" to be filled in before applying the filter
    – Kode
    Apr 8, 2015 at 19:41
  • Any suggestions on how to create a filtered calendar view with JSOM? I believe we need to set the calendar columns first
    – Kode
    Apr 17, 2015 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.