2

In my page I have two dropdowns, the second one depends on the choice of the first and this works, and the CAML query works, too.

How can I use $().SPServices.SPCascadeDropdowns to run a CAML query on the parent dropdown? I just want to run the filter on it. Is there an example of how to do this? It seems like SPCascadeDropdowns only works on the child; but I want to filter on the parent too.

But this should be the same filtering to run on just a single dropdown.

Here is what I am trying out to work on the filtering of the parent. I wasn't sure how to do this, so in my experiment I've set the parent and child to the same thing (althought it doesn't work), but I don't even know if you can use SPCascadeDropdowns this way:

    //Set up the cascading dropdowns for the parent Category dropdown
$().SPServices.SPCascadeDropdowns({
    relationshipWebURL: "",     //uses current site if left blank
    relationshipList: "TicketCategories",
    relationshipListParentColumn: "Category",
    relationshipListChildColumn: "Category",
    relationshipListSortColumn: "Title",
    parentColumn: "Category",
    childColumn: "Category",
    CAMLQuery: "<Leq><FieldRef Name='" + helpdesk.catleveltitle + "'/><Value Type='Text'>" + helpdesk.catlevel + "</Value></Leq>",
    CAMLQueryOptions: "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>", // Added in 2013.01
    listName: $().SPServices.SPListNameFromUrl(), 
    promptText: "",
    simpleChild: true,          // Added in v0.6.2
    selectSingleOption: false,      // Added in v0.6.2
    matchOnId: false,           // Added in v0.7.1
    completefunc: null,
    debug: false
});

The child dropdown works and filters perfectly based on what is selected in the parent.

//Set up the cascading dropdowns for the SubCategory dropdown
$().SPServices.SPCascadeDropdowns({
    relationshipWebURL: "",     //uses current site if left blank
    relationshipList: "TicketSubCategories",
    relationshipListParentColumn: "Category",
    relationshipListChildColumn: "Title",
    relationshipListSortColumn: "Title",
    parentColumn: "Category",
    childColumn: "SubCategory",
    CAMLQuery: "<Leq><FieldRef Name='" + helpdesk.catleveltitle + "'/><Value Type='Text'>" + helpdesk.catlevel + "</Value></Leq>",
    CAMLQueryOptions: "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>", // Added in 2013.01
    listName: $().SPServices.SPListNameFromUrl(), 
    promptText: "",
    simpleChild: false,         // Added in v0.6.2
    selectSingleOption: false,      // Added in v0.6.2
    matchOnId: false,           // Added in v0.7.1
    completefunc: function(){
        var thisSelect = "td span select[title='SubCategory']";
        DisplayDependencies(thisSelect);    //Do it when it loads
        $(thisSelect).change( function(){
            DisplayDependencies(thisSelect);  //and do it when it changes
        });
    }, //end completefunc()
    debug: false
});

I was hoping for a simple answer, but since I've been asked to show code, then now I have to explain it:

There are two lists which feed the dropdowns: Categories and SubCategories. Each of those has the name of the category as the Title column, and it has a second column called catlevel with a number column by which I can filter which items will show in the dropdowns based on what user group the current user is in (hence the helpdesk.catlevel variable).

After that, the child dropdown should only show subcategories that belong to each category. (the child dropdown works perfectly).

So I'm trying to add the caml query to the parent.

2

Figured it out! You can't do it with SPServices.SPCascadeDropdowns, but you CAN do it with SPServices.SPFilterDropdown!

This works perfectly!

    //Filter the Category dropdown
$().SPServices.SPFilterDropdown({
    relationshipWebURL: "",
    relationshipList: "TicketCategories",
    relationshipListColumn: "Title",
    relationshipListSortAscending: true,  // Added in 2013.01
    relationshipListSortColumn: "Title",
    columnName: "Category",
    listName: $().SPServices.SPListNameFromUrl(),
    promptText: "",
    noneText: "(None)",
    CAMLQuery: "<Leq><FieldRef Name='" + helpdesk.catleveltitle + "'/><Value Type='Text'>" + helpdesk.catlevel + "</Value></Leq>",
    CAMLQueryOptions: "<QueryOptions></QueryOptions>",
    completefunc: null,
    debug: false
});
0

There's caml attribute in the spcascade. Please post the code you are using and I can update it.

Till then, you can form a caml query and put it in the spcascade according to your requirement.

`CAMLQuery: "<Eq><FieldRef Name='Unit'/><Value Type='Text'>Unit 1</Value></Eq>"`

This call will limit the Departments to those that are in the selected Unit on selection of Unit. Ref

  • I have the caml part right. I just don't know how to make it work on just a single dropdown (or just on the parent). What do I set for parentColumn and childColumn if I only want to operate on one dropdown? – bgmCoder Dec 5 '15 at 19:27
  • I've added the code you requested. Please make the adjustment for the parent call. – bgmCoder Dec 5 '15 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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