2 (or more) lookups from the same source column in the same form

Apr 16, 2010 at 7:45 AM

I have had a lot of problems getting source lookup to run against multiple target fields, from a single source field.

ie.

var ccd1 = new cascadeDropdowns("Col1", "Col2", "Col1", "List1", "Title");
var ccd1 = new cascadeDropdowns("Col1", "Col3", "Col4", "List2", "Title");

I replaced the FilterChooicesForMyChild function with the following code to force the javascript to resolve each lookup in series as attempting in parrallel (current code) was only resolving the last target field.

There is a 150 millisecond delay on each call to allow time for the http_request to be satisified.  Until the request is satisfied, the recurse will keep looping.

 

function FilterChooicesForMyChild(triggerObject) {
	if (!setupComplete) return;  //security in IE not to trigger filter on load
	var wssSvc = new WssSvcCall();
	i = 0;
	wssSvc.completed = true;
	recurseFilter(triggerObject, wssSvc, i);
}


function recurseFilter(triggerObject, wssSvc, i)
{
	if (wssSvc.completed == false)
	{
		setTimeout(function(){recurseFilter(triggerObject, wssSvc, i)}, 150);
		return;
	}
	if (i >= CascadingDropdowns.length) return;
	if(CascadingDropdowns[i].parentLookup.Object == triggerObject || CascadingDropdowns[i].parentLookup.Opthid == triggerObject) 
	{
		var CascadingDropdown = CascadingDropdowns[i];
		wssSvc = new WssSvcCall();
		wssSvc.soapQuery = getQuery2Run(CascadingDropdown);
		wssSvc.url = wssSvcUrl;
		wssSvc.cascadingDropdown = CascadingDropdown;
		wssSvc.completed = false;
		wssSvc.returnFunctionName = function() { filterChildLookup(wssSvc.cascadingDropdown, wssSvc);}
		wssSvc.Submit();
		setTimeout(function(){recurseFilter(triggerObject, wssSvc, ++i)}, 150);
	}
	else
	{
		recurseFilter(triggerObject, wssSvc, ++i);
	}
}

I also modified the function filterChildLookup to set the completed flag.

 

function filterChildLookup(CascadingDropdown, WssSvc) {
  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 = "";
		}
		WssSvc.completed = true;  // New Code Here
	 } else {
		alert('There was a problem with the request.');
		WssSvc.completed = true;  // New Code Here
	 }
  }
}

 

Dec 21, 2010 at 4:52 PM

Did anyone get this to work for filtering 2 or more child fields based on the same source (parent) field?