Passing array as argument...

Questions, tips and tricks and techniques for scripting in Servoy

Passing array as argument...

Postby djlapin » Thu Mar 08, 2012 2:25 am

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
djlapin
 
Posts: 309
Joined: Fri Feb 18, 2011 9:36 am
Location: San Francisco, CA

Re: Passing array as argument...

Postby mboegem » Thu Mar 08, 2012 4:03 pm

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);
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1532
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Passing array as argument...

Postby kwpsd » Thu Mar 08, 2012 7:50 pm

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);
   }   
}
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 635
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: Passing array as argument...

Postby djlapin » Thu Mar 08, 2012 8:24 pm

Returning the array did the trick.

Thanks so much,
Don
djlapin
 
Posts: 309
Joined: Fri Feb 18, 2011 9:36 am
Location: San Francisco, CA


Return to Methods

Who is online

Users browsing this forum: No registered users and 1 guest

cron