SharePoint list - Cascading Lookup with default parent value selected and XSL parameters

I might have a hard time explaining this, but bear with me.

I'm building a workflow on a SharePoint task list and want the list of available actions to be restricted based on the current status of the workflow.

As such, I have implemented a cascading lookup solution from codeplex which uses javascript.  It's a client side solution http://spcd.codeplex.com/ and it works great, but it requires the user must physically make a selection from the parent STATUS column before it restricts the list of available ACTIONS on the child drop down.  

What I want to do is implement the solution whereby the ACTION child column automatically gets its list of available values from STATUS parent column without the user needing to do anything.  

Suggestions?


drewberryliciousAsked:
Who is Participating?
 
RaphilassConnect With a Mentor Commented:
ok you may have more success posting in the Javascript  Q/A's but I think i may be able to help.  The script is triggered from to the handler the is added by the addhandler function.
if(CascadingDropdowns[i].parentLookup.isDropDown) {
   CascadingDropdowns[i].parentLookup.Object.onchange = function() { FilterChooicesForMyChild(this); }
  }
  else {
   CascadingDropdowns[i].parentLookup.Opthid.onpropertychange = function() { FilterChooicesForMyChild(this); }
  }
 
My guess it to get it to populate correctly on the page load,  you need to add this javascript to the DDL on load event.  In the DropDownList tag of the HTML,  on the on load event add something like this...
onload="javascript: FilterChooicesForMyChild(this);"  <--- check the spelling of choices also,  is the function spelt like this.
Good luck, hope this helps
 
0
 
drewberryliciousAuthor Commented:
Here's the code I'm referencing in a sharepoint library.

I've then created a CEWP which contains the following

  <script type="text/javascript" src="http://xsite/sites/ats/solution/spcd.js"></script>
  <script type="text/javascript">
    var ccd1 = new cascadeDropdowns("ActionStatus", "ActionSubStatus", "ParentStatus", "Action Sub Status", "Title");
  </script>


/* 
/*  SharePoint JavaScript based cascaded dropdowns
/*  Published on spcd.codeplex.com
/*  Visit www.sharepointboris.net for more SharePoint tips and Tricks
/*  Tested on SharePoint 3.0 / 2007
*/ 

var setupComplete = false;
var wssSvcUrl = L_Menu_BaseUrl + "/_vti_bin/lists.asmx";
//Initiate function
function addHandler() {
	for (i = 0; i < CascadingDropdowns.length; i++) {
		if(CascadingDropdowns[i].parentLookup.isDropDown) {
			CascadingDropdowns[i].parentLookup.Object.onchange = function() { FilterChooicesForMyChild(this); }
		}
		else {
			CascadingDropdowns[i].parentLookup.Opthid.onpropertychange = function() { FilterChooicesForMyChild(this); }
		}
	}
	setupComplete = true;
}

//support functions
function getField(fieldType,fieldTitle) {   
     var docTags = document.getElementsByTagName(fieldType);   
     for (var i=0; i < docTags.length; i++) {   
         if (docTags[i].title == fieldTitle) {   
             return docTags[i];   
         }   
     }   
     return false;   
}  

//Object for working with web services
function WssSvcCall() {
	this.soapQuery = "";
	this.url = "";
	this.returnFunctionName = function() { return; };
	
	this.Submit = function() {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = this.returnFunctionName;
      http_request.open('POST', this.url, true);
      http_request.setRequestHeader("Content-type", "application/soap+xml");
      http_request.setRequestHeader("Content-length", this.soapQuery.length);
      http_request.send(this.soapQuery);
   }
}

//Object to hold the lookup field and needed properties
function LookupField(LookupFieldTitle) {
	this.Object = false;
	this.Opthid = false;
	this.isDropDown = true;
	
    if(getField('select',LookupFieldTitle))
    {
        //if lookup has 19 or less items - SELECT
        this.Object = getField('select',LookupFieldTitle);
    }
    else
    {
        //if it has 20 or more items - INPUT
        this.Object = getField('input',LookupFieldTitle);
        this.Opthid = document.getElementById(this.Object.optHid);
		this.isDropDown = false;
    }
}

var CascadingDropdowns = new Array();
//Object to hold cascading relationship info
function cascadeDropdowns(ParentDropDownTitle, ChildDropDownTitle, Child2ParentFieldIntName, ChildListNameOrGuid, ChildLookupTargetField) {
	this.parentLookup = new LookupField(ParentDropDownTitle);
	this.childLookup = new LookupField(ChildDropDownTitle);
	this.childList = ChildListNameOrGuid;
	this.child2ParentLink = Child2ParentFieldIntName;
	this.childLookupTargetField = ChildLookupTargetField;

	CascadingDropdowns.push(this);
}

function FilterChooicesForMyChild(triggerObject) {
	if(!setupComplete) return; //security in IE not to trigger filter on load
	for(i = 0; i < CascadingDropdowns.length; i++) {
		if(CascadingDropdowns[i].parentLookup.Object == triggerObject || CascadingDropdowns[i].parentLookup.Opthid == triggerObject) {
			var CascadingDropdown = CascadingDropdowns[i];
			var wssSvc = new WssSvcCall();
			wssSvc.soapQuery = getQuery2Run(CascadingDropdown);
			wssSvc.url = wssSvcUrl;
			wssSvc.returnFunctionName = function() { filterChildLookup(CascadingDropdown); }
			wssSvc.Submit();
		}
	}
}

function getQuery2Run(CascadingDropdown) {
	var selectedId;
	if(CascadingDropdown.parentLookup.isDropDown) {
		selectedId = CascadingDropdown.parentLookup.Object.options[CascadingDropdown.parentLookup.Object.selectedIndex].value;
	}
	else {
		selectedId = CascadingDropdown.parentLookup.Opthid.value;
	}
	var result = '<?xml version="1.0" encoding="utf-8"?>' +
	'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
	  '<soap12:Body>' +
		'<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">' +
		'<listName>' + CascadingDropdown.childList + '</listName>' +
			'<query>' +
				'<Query>' +
				(selectedId==0?'':'<Where><Eq><FieldRef LookupId="TRUE" Name="' + CascadingDropdown.child2ParentLink + '" /><Value Type="Counter">' + selectedId + '</Value></Eq></Where>') + 
				'<OrderBy><FieldRef Name="' + CascadingDropdown.childLookupTargetField + '" /></OrderBy>' +
				'</Query>' +
			'</query>' +
			'<viewFields><ViewFields>' +
				'<FieldRef Name="' + CascadingDropdown.childLookupTargetField + '" /><FieldRef Name="ID" />' + 
			'</ViewFields></viewFields>' +
		'</GetListItems>' +
	  '</soap12:Body>' +
	'</soap12:Envelope>'
	return result;
}

function filterChildLookup(CascadingDropdown) {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		var xmlResult = parseXML(http_request.responseText);
		var resultNodes = xmlResult.getElementsByTagName('z:row');
		if(CascadingDropdown.childLookup.isDropDown) {
			var startAt = 0;
			if(CascadingDropdown.childLookup.Object.options[0].value == 0) startAt = 1;
			CascadingDropdown.childLookup.Object.options.length = startAt;
			for(y = 0; y < resultNodes.length; y++) {
				CascadingDropdown.childLookup.Object.options[y + startAt] = new Option(attributeValue(resultNodes[y], "ows_" + CascadingDropdown.childLookupTargetField), attributeValue(resultNodes[y], "ows_ID"), false, false);
				if(CascadingDropdown.childLookup.Object.options.length > 0) CascadingDropdown.childLookup.Object.options[0].selected = "selected";
			}
		}
		else {
			var choices = CascadingDropdown.childLookup.Object.choices;
			if(choices.substr(choices.indexOf("|"),3) == "|0|") choices = choices.substr(0, choices.indexOf("|")+2);
			var choicesArr = new Array();
			for(y = 0; y < resultNodes.length; y++) {
				choicesArr.push(attributeValue(resultNodes[y], "ows_" + CascadingDropdown.childLookupTargetField) + "|" + attributeValue(resultNodes[y], "ows_ID"));
			}
			choices += (choicesArr.length==0?"":"|") + choicesArr.join('|');
			CascadingDropdown.childLookup.Object.choices = choices;
			CascadingDropdown.childLookup.Object.value = "";
			CascadingDropdown.childLookup.Opthid.value = "";
		}
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

//xml parsing support functions
function parseXML(inputString) {
	if (window.DOMParser) {
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(inputString,"text/xml");
	}
	else { // Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(inputString); 
	}
	return xmlDoc;
}

function attributeValue(node, attributeName) {
	var attributesCollection = node.attributes;
	for(atv = 0; atv < attributesCollection.length; atv++) {
		if(attributesCollection[atv].name == attributeName) return attributesCollection[atv].value
	}
	return "";
}

//Start the party after the DOM is loaded
_spBodyOnLoadFunctionNames.push('addHandler');

Open in new window

0
 
drewberryliciousAuthor Commented:
BTW - I'm not a coder and I've just copied in the contents of the javascript file.   Please be kind to me!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.