Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Populate Drop-down list from Access Database...

Avatar

Level 1
I've searched the forum and the help file to try and find the solution to my problem but am not having any luck. I am not experienced at all with Javascript and am pretty sure that is the problem is. The script I'm using is included below. I'm using a table by the name of Test and am trying to populate it with data from the column Dept_ID. I have the data connection established in the data view tab but get nothing in the drop down selection. If I bind the field to the column I only get the first value. <br /><br />Any suggestions would be appreciated. Thank you!<br />*******************************************************************<br />* This dropdown list object will populate two columns with data from a data connection.<br /><br /> sDataConnectionName - name of the data connection to get the data from. Note the data connection will appear in the Data View.<br /> sColHiddenValue - this is the hidden value column of the dropdown. Specify the table column name used for populating.<br /> sColDisplayText - this is the display text column of the dropdown. Specify the table column name used for populating.<br /><br /> These variables must be assigned for this script to run correctly. Replace <value> with the correct value.<br />*/ <br /><br />var sDataConnectionName = "<value>"; // example - var sDataConnectionName = "Test";<br />var sColHiddenValue = "<value>"; // example - var sColHiddenValue = "Dept_ID";<br />var sColDisplayText = "<value>"; // example - var sColDisplayText = "Dept_ID"<br /><br />// Search for sourceSet node which matchs the DataConnection name<br />var nIndex = 0;<br />while(xfa.sourceSet.nodes.item(nIndex).name != sDataConnectionName)<br />{<br /> nIndex++;<br />}<br /><br />var oDB = xfa.sourceSet.nodes.item(nIndex);<br />oDB.open();<br />oDB.first();<br /><br />// Search node with the class name "command"<br />var nDBIndex = 0;<br />while(oDB.nodes.item(nDBIndex).className != "command")<br />{<br /> nDBIndex++;<br />}<br /><br />// Backup the original settings before assigning BOF and EOF to stay<br />var sBOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("bofAction");<br />var sEOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("eofAction");<br /><br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayBOF", "bofAction");<br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayEOF", "eofAction");<br /><br />// Clear the list<br />this.clearItems();<br /><br />// Search for the record node with the matching Data Connection name<br />nIndex = 0;<br />while(xfa.record.nodes.item(nIndex).name != sDataConnectionName)<br />{<br /> nIndex++;<br />}<br />var oRecord = xfa.record.nodes.item(nIndex);<br /><br />// Find the value node<br />var oValueNode = null;<br />var oTextNode = null;<br />for(var nColIndex = 0; nColIndex < oRecord.nodes.length; nColIndex++)<br />{<br /> if(oRecord.nodes.item(nColIndex).name == sColHiddenValue)<br /> {<br /> oValueNode = oRecord.nodes.item(nColIndex);<br /> }<br /> else if(oRecord.nodes.item(nColIndex).name == sColDisplayText)<br /> {<br /> oTextNode = oRecord.nodes.item(nColIndex);<br /> }<br />}<br /><br />while(!oDB.isEOF())<br />{<br /> this.addItem(oTextNode.value, oValueNode.value);<br /> oDB.next();<br />}<br /><br />// Restore the original settings<br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sBOFBackup, "bofAction");<br />oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sEOFBackup, "eofAction");<br /><br />// Close connection<br />oDB.close();
2 Replies

Avatar

Former Community Member
You have entered the values you need (in the 1st 3 lines of code) in the comment and not in the actual running statement. Replace the <value> with the values that you have. <br /><br />Also the 1st parameter is not a table name but the name of your ODBC connection that you have to create before any of this will work. The data connection definition will point to the appropriate DB and associated table.

Avatar

Level 1
Thank you Paul. I just assumed that translated into the running statement. I will give that a try to see if it works. The 1st parameter is actually the data connection name that was created. I'm still trying to learn the terminology and didn't explain that correctly. Thanks again for your help. I will go through and correct the values.