Forum Discussion
cunderw
9 years agoCommunity Hero
Here is a little generic function that will take a record and convert it to an object.
/**
* @function
* @param {object} rec - the result of an ADO query
* @return {object} retVal - the record converted to a javascript object.
*/
function recordToObject(rec) {
var retVal = {};
try {
if(!rec.EOF) {
for(var i = 0; i < rec.Fields.Count; i++ ) {
retVal[rec.Fields.Item(i).Name] = rec.Fields.Item(i).Value == null ? "" : aqString.Trim(rec.Fields.Item(i).Value);
}
}
else {
Log.Warning("There is nothing in the record set");
}
}
catch(err) {
Log.Warning("There was an error building object. See additional information",err.message + "\n" + err.stack);
}
finally {
return retVal;
}
}
//you can then push the results to an array to call by index and column name.
function test() {
//code to get record
var elementList = [];
set.MoveFirst();
while(!set.EOF) {
elementList.push(recordToObject(set));
set.MoveNext();
}
Log.Message(elementList[0].columnName);
}