This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.



Mar 24, 2013, 2:02 PM
22 Posts

Array problem (@DbLookup)

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 5
Hi  

I have two combobox's: cbBetrieb and cbStandort. cbStandort uses the value on cbBetrieb to load only specific values. This works perfectly. To load the values in cbBetrieb I use the following code which works perfectly:

 

// create an emtpy array

var arr = new Array(" "); 

// append the retrieved values to the array  

var res = @Unique (@DbColumn ("", "vwLookup", 1)); 

var list = arr.concat(res); 

return list;


NB: I add a empty option to the beginning of the list.  

I would now like to do the same with cbStandort - here I am using the value in cbBetrieb to load the values from a view using @DbLookup. The @DbLookup is working perfectly but I am getting errors when I try and add an empty option to the array. Here is the code I am using: 

// get the current selected betrieb

var categoryComp = getComponent("cbBetrieb");

if (categoryComp == null) return "";

var category = categoryComp.getValue();

if (category == "") return "";

// create an empty array

var arr = new Array(" "); 

// get the values for this betrieb

var res = @Unique (@DbLookup ("", "vwLookup", category, 2));

// now add the values to the empty array

var list = arr.concat(res); 

return list; 

I get the error as soon as I use the the second last line above (var list = arr.concat (res)) - if I just return res everything is hunky dorey, if I return list I get a runtime error. I am assuming that @DbLookup returns a different data type than @DbColumn does, no matter how I fiddle with the code I cannot get it to work correctly.

Any ideas? 

Greetings from Austria 
Ursus 


 


 
Mar 24, 2013, 4:24 PM
589 Posts
Re: Array problem (@DbLookup)
 How many values is the DbColumn returning?  I'm pretty sure that if multiple values are returned than an array is given back.  But if only one value is returned then the data type is a string.


Could that be the problem? 
Mar 24, 2013, 4:35 PM
22 Posts
Re: Array problem (@DbLookup)
 Hi David 

thank you for looking at this.  It was nice meeting you in person at IBMConnect :o) 

Nope - I don't think that's it - if I replace the @DbLookup with a @DbColumn then the code works as is... really odd?

Greetings from Austria 

Ursus 
Mar 24, 2013, 9:16 PM
589 Posts
Re: Array problem (@DbLookup)
 Hi!  
 

Nice to "see" you here!  :)
 
Hmmm.. Not sure I know the issue without getting a hold of a working example.  So let me give you a couple thoughts...

Rather then doing the blank array thing where you merge the 2 arrays...  have you tried getting your blank in via a manual entry to the list?  Using @Text("") or something like that?  Just wondering if that would work. 

The other alternative might be to instead of doing an @DbLookup and putting your code in the combobox itself...  I'd sooner create a SSJS function that gets the data.  The key though is that the function needs to return a vector I believe. I forget if there's a NotesIn9 on this but there's a blog post that might be helpful.  http://www.teamspace.ca/TeamSpace/Blog.nsf/dx/populate-xpage-combobox-choices-from-notes-multi-value-field.htm


Again - what you're doing should work I think - or at least I don't know what's wrong with it but maybe you can get back to forward progress with either of those suggestions. 


Dave 
Mar 25, 2013, 5:19 AM
22 Posts
Re: Array problem (@DbLookup)
Hi David

if you would like me to send you a working example, no problem. Just drop me a line at ursus dot schneider at gmail dot com. 

Manual entry: Yes, I have tried that but I could not get it to work. 

Link: I checked the link and will give that a try this evening


Thank you for your help 
Ursus 

 
Mar 29, 2013, 8:41 AM
589 Posts
Video Solution
If anyone finds this thread and wants more info - I solved this problem in NotesIn9 Show 104 - http://notesin9.com/index.php/2013/03/26/notesin9-104-viewer-question-comboboxes /

This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.