Hi Sunil.
There are a number of ways to achieve this. You will basically want to
- read your CSV file
- build-up your list of names in an array
- create a choice constraint out of the array
- replace the constraint in your drop-down list with your new one
- store any other CSV data you want (either as parameters or as a JSON object)
- add a task to your drop-down parameter to grab the photo path out of your stored data
- set a parameter for your 'photo path' to the value from your stored data
Attached is an example that does this with your CSV schema and uses the approach where all of the CSV data is stored as an object.
<abs contexttype="opengear" dblinqport="2222" id="_top">
<meta>
<params>
<param access="1" maxlength="0" name="Selected Photo" oid="Selected_Photo" stateless="true" type="STRING" value="" widget="label"/>
<param access="1" constrainttype="INT_CHOICE" name="Selected Index" oid="Selected_Index" precision="0" stateless="true" type="INT32" value="-1" widget="combo">
<constraint key="-1">Nothing Loaded</constraint>
</param>
</params>
</meta>
<param expand="true" height="39" left="26" oid="Selected_Index" top="29" width="238">
<task tasktype="ogscript">if (this.getValue() >= 0)
{
var csvData = ogscript.getObject('csv-data');
if (csvData != null && csvData.length > this.getValue())
{
var rowData = csvData[this.getValue()];
params.setValue('Selected_Photo', 0, rowData.photo);
}
}</task>
</param>
<param expand="true" height="38" left="22" oid="Selected_Photo" style="size:Small;bg#dark;fg#panelfg;" top="99" width="643">
<task tasktype="ogscript">//To show a preview, we need to turn the file system path into a URL
var filePath = this.getValue();
filePath = filePath.split('\\').join('/');
filePath = filePath.split(' ').join('%20');
filePath = 'file:/' + filePath;
ogscript.setStyle('photo-preview', 'bg-u:' + filePath);</task>
</param>
<abs height="115" id="photo-preview" left="673" style="bg-fill:fit;bg#dark;bdr:shadow;" top="22" width="151"/>
<button buttontype="push" height="44" left="270" name="Load" top="27" width="94">
<task tasktype="ogscript">function processCSV(fileContent)
{
if (fileContent == null)
{
ogscript.debug("CAN'T LOAD FILE");
return;
}
var allCSVData = [];
var nameList = [];
var rows = fileContent.split('\n');
var dataByColumn = []; //It is more efficient if we only call "SET" on the parameters once
for (var r = 1; r < rows.length; r++)
{
var cols = rows[r].trim().split(',');
var csvRow = {};
csvRow.name = cols[0];
csvRow.photo = cols[1];
csvRow.place = cols[2];
csvRow.place_image = cols[3];
if (csvRow.name.length > 0)
{
allCSVData.push(csvRow);
nameList.push(csvRow.name);
}
}
ogscript.putObject('csv-data', allCSVData);
params.replaceConstraint('Selected_Index', params.createIntChoiceConstraint(nameList));
ogscript.debug("NAMES: " + nameList.length);
}
ogscript.asyncPost('Employee_Photo.csv', null, processCSV);</task>
</button>
</abs>
#DashBoard