Page 1 of 1

Passing array as argument...

PostPosted: Thu Mar 08, 2012 2:25 am
by djlapin
How can I get the following to work?

Code: Select all
function UTIL_choiceListToArray(valueList, arrayName, arrayType) {
   if(valueList && arrayName) {
      var querytext = "";
      if((arrayType) && (arrayType == 'name')) {
         querytext = "SELECT choice_list.chc_item_name FROM choice_list WHERE ";
      } else {  // default to obtaining the code value --
         querytext = "SELECT choice_list.chc_item_code FROM choice_list WHERE ";
      }
      querytext += "choice_list.valuelist_name = \'" + valueList + "\'";
      var ds = databaseManager.getDataSetByQuery('SELPA_Mgr_SQL', querytext, null, 1000);
      ds.sort(1,true);
      arrayName = ds.getColumnAsArray(1);
   }   
}


Right now the dataset is populated, but the array is empty. I've tried passing both an array object and a string (name) as arrayName.

Thank you,
Don

Re: Passing array as argument...

PostPosted: Thu Mar 08, 2012 4:03 pm
by mboegem
Hi Don,

what is this 'arrayName' argument in the method?
Is this a string referencing a global/form variable or something?

if so and - like you say - the dataset is populated and ds.getColumnAsArray(1) gives you the array you want to store
this should do the job in case of a global variable:
Code: Select all
globals[arrayName] =  ds.getColumnAsArray(1);

Re: Passing array as argument...

PostPosted: Thu Mar 08, 2012 7:50 pm
by kwpsd
You could do something like this:

Code: Select all
var arrayName = UTIL_choiceListToArray(valueList, arrayType)

function UTIL_choiceListToArray(valueList, arrayType) {
   if(valueList && arrayName) {
      var querytext = "";
      if((arrayType) && (arrayType == 'name')) {
         querytext = "SELECT choice_list.chc_item_name FROM choice_list WHERE ";
      } else {  // default to obtaining the code value --
         querytext = "SELECT choice_list.chc_item_code FROM choice_list WHERE ";
      }
      querytext += "choice_list.valuelist_name = \'" + valueList + "\'";
      var ds = databaseManager.getDataSetByQuery('SELPA_Mgr_SQL', querytext, null, 1000);
      ds.sort(1,true);

      return ds.getColumnAsArray(1);
   }   
}

Re: Passing array as argument...

PostPosted: Thu Mar 08, 2012 8:24 pm
by djlapin
Returning the array did the trick.

Thanks so much,
Don