Thursday, November 4, 2010

Drop Dead Drop Downs



When consuming a dataset created from a table with a key and description, by selecting at the top element and splitting the value and display, we can get a return value in the xmlDocument to post the foreign key and bind the joins together.

In this case the segment of xml is like:




->editregion
id->1
Desc->North Los Angeles
vpid->1227
vpname->Kolenda, Kathleen
vpstring->Kolenda, Kathleen
->/editregion


Then if the default value is -1, the value returned can be handled by determining if the result sent is a -1, in which case the source for VPName is the value (or in this case the VP’s Employee ID Number). What is funky is that the VPName will be the Display Name rather than the value if it’s an edit but if left untouched the VPName will be the Display Value. My solution is to load the table with a VPString field that doesn’t show and has the original name so that if they don’t match I know to use the VPName field but if they do I can use the VPID field.

With this code segment to load the repeating group in the main data section, I can get around the funkyness…


function LoadESSCRegions()
{ // Get the list of Services. var
regions = Document.GetDOM("AsRegionsList").selectNodes("//REGIONS");

// If nothing was found, then return; there will be no items to
insert.
if(regions == null)
{

XDocument.UI.Alert("Error-> Unable to load Regions List");
return;
}

var reg;

while
(reg = regions.nextNode())
{
var row =
XDocument.DOM.selectSingleNode("//my:myFields/my:RegionsTable/my:EditRegions");
row = row.cloneNode(true);
row.selectSingleNode("my:ESSCRegion_ID").text
= reg.selectSingleNode("ESSCRegion_ID").text;
row.selectSingleNode("my:RegionDescription").text =
reg.selectSingleNode("Description").text;
row.selectSingleNode("my:RegionIsActive").text =
reg.selectSingleNode("IsActive").text;
if (reg.selectSingleNode("RVP") ==
null)
row.selectSingleNode("my:RVPID").text = "-1"
else
row.selectSingleNode("my:RVPID").text = reg.selectSingleNode("RVP").text;

if (reg.selectSingleNode("NAME") == null)
row.selectSingleNode("my:RVPString").text = ""
else
row.selectSingleNode("my:RVPString").text =
reg.selectSingleNode("NAME").text;

var parent =
XDocument.DOM.selectSingleNode("//my:myFields/my:RegionsTable");
parent.appendChild(row);
}

}

No comments: