Environment: windows2003/TeamSite671SP1
Code attached: model.js/datacapture.cfg + enumeration.js/datacapture.cfg + displaydropdown.ipl
I am dealing with a code setup issue here at this large European retailer
The issue is that on editing a dcr, the featureselect dropdown in a Feature Information container contains a stored xml key/value pair, but the FormAPI fails to capture the value or label from the xml. Instead it shows an inital empty value.
The setup is the datacapture.cfg field
[html]
[/html]
is overridden with the model.js call in init():
[html]
while (IWDatacapture.getItem("/model/Feature Information/modelFeature["+j+"]/modelFeatureId")) {
var featureid=IWDatacapture.getItem("/model/Feature Information/modelFeature["+j+"]/modelFeatureId");
var featureitem=IWDatacapture.getItem("/model/Feature Information/modelFeature["+j+"]/modelFeatureValue");
var featurepresent=IWDatacapture.getItem("/model/Feature Information/modelFeature["+j+"]/modelFeaturePresent");
var featureselect=IWDatacapture.getItem("/model/Feature Information/modelFeature["+j+"]/modelFeatureSelect");
var fieldname=featureselect.getName();
if (featureselect.getValue() != null) {
DisplayCorrectDropDown(featureid.getOptions()[featureid.getValue()].value, featureselect.getOptions()[featureselect.getValue()].value, fieldname);
//var fieldvalue=featureselect.getOptions()[featureselect.getValue()].value;
//alert(fieldvalue);
featureitem.setVisible(false);
featurepresent.setVisible(false);
featurepresent.setRequired(false);
//var featurelabel = featureselect.getOptions()[featureselect.getValue()].text;
//alert(featurelabel);
//featureselect.getOptions()[featureselect.getValue()].text;
//featureselect.setVisible(true);
}
else if (featurepresent.getValue() != null) {
featurepresent.setVisible(true);
featurepresent.setRequired(true);
featureselect.setVisible(false);
}
else {
featureitem.setVisible(true);
featureselect.setVisible(false);
}
j++;
}
[/html]
I think the reason for the issue is that the featureselect dropdown is generated on the server side via the js method
[html]
function DisplayCorrectDropDown(featureid, featureselect, fieldname) {
var params = new Object();
params.workarea = IWDatacapture.getWorkarea();
params.featureid = featureid.toString();
params.featureselect = featureselect.toString();
params.fieldname = fieldname;
var server = window.location.hostname;
IWDatacapture.callServer("http://"+server+"/iw-bin/displaydropdown.ipl", params);
}
[/html]
The perl code effectively generates the javascript and inserts it into the client:
[html]
sub checkfeature() {
my $fullfilepath=$File::Find::name;
$fullfilepath=~s|\/|\\|g;
if (-f $fullfilepath) {
open(FILE, "$fullfilepath");
my $xmloutput;
while(){
$xmloutput .= $_;
}
close(FILE);
my $rootnode=TeamSite:

CRnode->new($xmloutput);
if ($rootnode ne "") {
my $feature_id_to_compare = $rootnode->value(featureName);
if ($featureid eq $feature_id_to_compare) {
my $feature_select = $rootnode->value(featureSelectList);
if ($feature_select ne "") {
my $enumselectpath = $workarea."/templatedata/Content/Enumeration/data/en_GB/feature/".$feature_select;
$arrayoutput="var optionArray = new Array();\n";
my $counter=0;
if (-f $enumselectpath) {
open(FILE, "$enumselectpath");
my $xmloutput;
while(){
$xmloutput .= $_;
}
close(FILE);
my $rootnode=TeamSite:

CRnode->new($xmloutput);
if ($rootnode ne "") {
my
@selectlist = $rootnode->get_node_list('enumerationItem');
foreach my $listitem (
@selectlist) {
my $key=$listitem->value('enumerationItemKey');
my $value=$listitem->value('enumerationItemValue');
$arrayoutput.="optionArray[$counter] = new Option(\"$value\",\"$key\");\n";
$counter++;
}
}
}
}
$jsoutput=$arrayoutput;
$jsoutput.="api.IWDatacapture.getItem(\"$fieldname\").setOptions(optionArray);\n";
$jsoutput.="api.IWDatacapture.getItem(\"$fieldname\").setVisible(true);\n";
}
}
}
}
[/html]
I suspect the client side cannot evaluate the xml in the DCR if the server side actually sets this dropdown via these 3 lines:
[html]
$jsoutput=$arrayoutput;
$jsoutput.="api.IWDatacapture.getItem(\"$fieldname\").setOptions(optionArray);\n";
$jsoutput.="api.IWDatacapture.getItem(\"$fieldname\").setVisible(true);\n";
[/html]
My question is: how do I get this item correctly displayed in the dropdown in the form? Do I have to change the architecture of this feature dramatically?
In the formapi documentation there is a short section on Restoring Dynamic Options. The following is stated:
"The best solution is to ensure that the user script restores the options of a selection if the value does not have the right label. This requires querying the option and checking the label of the selected option. If it is not correct, a new options array is created that adjusts the problem. Because the user script usually has the ability to regenerate the option, this approach is the most flexible."
Does this apply to my situation? Anyone applied this solution and can give me a hint on how to code this in FormAPI?