SPCascadeDropdowns with CAMLQuery

Coordinator
Dec 28, 2011 at 3:37 PM

From http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPCascadeDropdowns by Lovekush Today at 5:56 AM

Very Nice article!!! able to set the cascading dropdown but not able to filter through CAMLQuery parameter. Please find my scenario as mentioned below

I have 2 dropdown(Country and City) as lookup on my newform.aspx page of the custom list(Cascading) in Sharepoint 2010
Country List: contains the Countries entry
City List (relationship list) contains: Cities entry(text type), Country Column as lookup from the Country List and MainCities(typeText)
the custom List Cascading contains both Country and City column as lookup.
City List is the relationshiplist which contains 1 more column called MainCities(text type) which will have value 1 if the City is major otherwise it will have null value or 0
I want to filter the cities based on the Country and only the Major cities(column MainCities=1)
when i pass the CAMLQuery Parameter as mentioned below the script stopped working(not even setting the cascading dropdown)

<script language="javascript" src="/sites/Test/JSLib/jquery-1.5.2.min.js" type="text/javascript"></script><script language="javascript" src="/sites/Test/JSLib/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script><script type="text/javascript">
$(document).ready(function() { 
  $().SPServices.SPCascadeDropdowns({ 
    relationshipList: "CityList",
    relationshipListParentColumn: "Country",
    relationshipListChildColumn: "City",
    parentColumn: "Country",
    childColumn: "City", 
    CAMLQuery: "<Eq><FieldRef Name="MainCities" /><Value Type="Text">1</Value></Eq>",
    debug: true
  });
});
</script>

Please let me know what i am missing

Coordinator
Dec 28, 2011 at 4:04 PM

I think it's a simple matter of quotes. You've got double quotes inside double quotes. Use single quotes instead:

CAMLQuery: "<Eq><FieldRef Name='MainCities' /><Value Type='Text'>1</Value></Eq>",

M.

Dec 29, 2011 at 12:01 PM

Thanks sympmarc, yeah that doubble quotes was the mistake.

1 more query i have regarding the cascading dropdown as mentioned below

On Country selection Initially i have to populate the Main Cities(which is working) and i have a checkbox on checking that checkbox it should show all rest of the cities and on uncheck only Main Cities should populate again in cities drop down, for that i put the casacading script for checkbox checked and unchecked as mentioned in below code snippet

<script language="javascript" src="/sites/Test/JSLib/jquery-1.5.2.min.js" type="text/javascript"></script><script language="javascript" src="/sites/Test/JSLib/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script><script type="text/javascript">

    $(document).ready(function() { 

   $().SPServices.SPCascadeDropdowns({          

           relationshipList: "CityList",

           relationshipListParentColumn: "Country",

           relationshipListChildColumn: "City",

           parentColumn: "Country",

           childColumn: "City",            

                       debug: true        

                   }); 

           // When Checkbox checked   

           $('#ctl00_m_g_69d32b1c_437b_44ea_86ca_136f0df069b5_ctl00_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00').click(function(){

          if (this.checked) {

          $().SPServices.SPCascadeDropdowns({          

                       relationshipList: "CityList",

                      relationshipListParentColumn: "Country",

                      relationshipListChildColumn: "City",

                      parentColumn: "Country",

                     childColumn: "City",            

                      debug: true                  

                  });

       } 

      //When Checkbox unchecked 

       else {

             $().SPServices.SPCascadeDropdowns({          

                      relationshipList: "CityList",

                      relationshipListParentColumn: "Country",

                      relationshipListChildColumn: "City",

                      parentColumn: "Country",

                     childColumn: "City",

                    CAMLQuery: "<Eq><FieldRef Name='MainCities' /><Value Type='Text'>1</Value></Eq>",                      

                     debug: true                    

                 });

          }

      }); 

   });

</script>

not sure once the cascading dropdown sets it doesnot change the binding on deselection of checkbox?

Please suggest me the way to achieve this.

 

Coordinator
Dec 29, 2011 at 2:04 PM

SPCascadeDropdown is built to be called once per column relationship. Calling it again may or may not do what you want - I never intended it for that use. It sets things up to "wire together" the two columns for the lifespan of the page.

M.