Monday, April 10, 2017

2 level Cascading Lookup using SP Services

Pre-requisites :

  • JQuery Reference
  • SP Services Reference
Code :


<script type="text/javascript" src="../../SiteAssets/Scripts/jquery.2.1.3.min.js"></script>
<script type="text/javascript" src="../../SiteAssets/Scripts/jquery.SPServices-2014.02.js"></script>  
<script type="text/javascript">  
$(document).ready(function ()  
{  
$().SPServices.SPCascadeDropdowns({
  relationshipWebURL: "",
  relationshipList: "StateList",
  relationshipListParentColumn: "LookupCountry",
  relationshipListChildColumn: "State",
  parentColumn: "LookupCountryParent",
  childColumn: "LookupStateParent",
  debug: false
});
$().SPServices.SPCascadeDropdowns({
  relationshipWebURL: "",
  relationshipList: "CityList",
  relationshipListParentColumn: "LookupState",
  relationshipListChildColumn: "City",
  parentColumn: "LookupStateParent",
  childColumn: "LookupCityParent",
  debug: false
});

});
</script>

Explanations:-

  1. relationshipList - The list which has parent/child relationship.
  2. relationshipListParentColumn - The lookup column in relationshipList.
  3. relationshipListChildColumn - The column which is dependent on relationshipListParentColumn.
  4. parentColumn - The lookup column in parent list/master.
  5. childColumn - The lookup column in parent list/master list.
Analogy:-

CountryList

Title

India
UK
US

StateList

State LookupCountry

MP              India
Karnataka   India


CityList

City             LookupState

Bangalore    Karnataka
Ujjain          MP

ParentList - This is the list where I want cascading lookups i.e. on change of Country respective State should come, and further city should load for respective states.

Title      LookupCountryParent     LookupStateParent     LookupCityParent

New      India                                    Karnataka                      Bangalore

No comments:

Post a Comment

Clearing Person/Group Values

To clear out or empty the values in person or group columns, how you do it depends on if the column is single-value or multi-value. For ...