How do I append a value to results of #DBlookup in xpages? - xpages

How do I append a value to results of #DBlookup in xpages?
I tried this but it does not seem to work.
var v = #DbLookup("","Setup","Setup","ModRationales").push("Other 2");
return v;
It shows 6.0 in my listbox.

First of all: #DbLookup returns a string when it looks up one value only, and it returns an array when it finds multiple values. I will therefore suggest that you use the DbLookupArray() function available as a xsnippet as this function always returns an array. It has other advantages too such as optional caching of the result.
Then it is just a matter of adding elements to the array using .push() on the result returned by DbLookupArray().
Your current lookup is most likely returning a single element - which in the case of #DbLookup is a string.

Got it:
var v = #DbLookup("","Setup","Setup","ModRationales");
v.push("Other");
return v;

Related

Nodejs - Read values of array as number instead of string

I created an array inside my own class in nodejs to store real values.
this.values = new Array();
and almost every second a new value is pushed to this array.
this.values.push(Number(dataset.c).toFixed(4));
Finaly I have a function where I need to provide the array in the argument list to do bollinger band calculation. This function need an array filled with real or integer values but in my array every value is stored as an string.
Is it possible to change this storage behaviour or how can I 'typecast' all the values in this array?
Best regards
Found a solution using the map-Function.
this.values.map(Number)
did the job.

Ampscript BuildRowsetFromString() fails on single item

I've been tasked with an ExactTarget task, which uses Ampscript. Trying to learn on the go here. See code snippet below:
%%[
Var #testString, #testOutput
Set #testString = Qwerty
Set #testOutput = BuildRowsetFromString(#testString,"~")
]%%
TestOutput:%%= v(#testOutput) =%%
The code works if the testString contains a ~, but when there is no ~ character in the string, the ouput is blank. Is this correct by design? Do I need to add a conditional to check for the presence of the ~ character?
That's the expected behavior. The BuildRowsetFromString() function alone isn't going to return any value when displayed, you're going to need to use Row() and Field() in order to pull the value out.
Using your example:
%%[
Var #testString, #testOutput
Set #testString = "Qwerty"
Set #testOutput = BuildRowsetFromString(#testString,"~")
]%%
RowCount: %%=RowCount(#testOutput)=%%
TestOutput: %%=v(#testOutput)=%%
The RowCount() function returns a value of 1, essentially saying it knows there's at least one 'row' in there. To display that one value, you'll need to wrap that value with Field() and Row():
TestOutput: %%=Field(Row(#testOutput,1),1)=%%
If you want to display other values in the string, say you were passing "Qwerty~Second~Third", you'll need to either change the number at the Row() function or perform a loop.
References
Using Loops
BuildRowsetFromString() Function

Cognos query calculation - how to obtain a null/blank value?

I have a query calculation that should throw me either a value (if conditions are met) or a blank/null value.
The code is in the following form:
if([attribute] > 3)
then ('value')
else ('')
At the moment the only way I could find to obtain the result is the use of '' (i.e. an empty character string), but this a value as well, so when I subsequently count the number of distinct values in another query I struggle to get the correct number (the empty string should be removed from the count, if found).
I can get the result with the following code:
if (attribute='') in ([first_query].[attribute]))
then (count(distinct(attribute)-1)
else (count(distinct(attribute))
How to avoid the double calculation in all later queries involving the count of attribute?
I use this Cognos function:
nullif(1, 1)
I found out that this can be managed using the case when function:
case
when ([attribute] > 3)
then ('value')
end
The difference is that case when doesn't need to have all the possible options for Handling data, and if it founds a case that is not in the list it just returns a blank cell.
Perfect for what I needed (and not as well documented on the web as the opposite case, i.e. dealing with null cases that should be zero).

Autocomplete function with underscore/JS

what is the proper way to implement an autocomplete search with undescore?
i have a simple array (cities) and a text input field ($.autocomplete). when the user enters the first letters in the auto-complete textfield, it should output an array with all the cities starting with the entered letters (term).
cities:
["Graz","Hamburg","Innsbruck","Linz","München","Other","Salzburg","Wien"]
eventlistener:
$.autocomplete.addEventListener("change", function(e){
var cities = cities_array;
var term = $.autocomplete.value;
var results = _.filter(cities, function (city){
return
});
console.log(results + "this is results");
});
I’ve tried it with _.contains, but it only returns the city when its a complete match (e.g Graz is only output when „Graz“ is entered but not when „Gr“ is entered).
the _.filter/._select collection at http://underscorejs.org/docs/underscore.html are not very clear for me and the closest i found here is filtering JSON using underscore.
but i don’t understand the indexOf part.
thx for any suggestions!
By using #filter and #indexOf, you can get quite close to a pretty decent autocomplete.
What #indexOf does is that it checks the string if it contains the inputVal.
If it does not contain it it'll return -1 therefore our predicate below will work without fail.
Another small trick here is that you (read I) wanted it to be possible to search for s and get a hit for Innsbruck and Salzburg alike therefore I threw in #toLowerCase so that you always search in lower case.
return _.filter(cities, function(city) {
return city.toLowerCase().indexOf(inputVal.toLowerCase()) >= 0;
});

groovy - findAll getting only one value

I'm struggling to find examples of findAll with groovy. I've got a very
simple code snippet that gets the property of a node and outputs it's
value. Except I'm only getting the last value when I'm looping through
a series of properties. Is there something I'm doing wrong here, this
seems really simple.
JcrUtils.getChildNodes("footer").findAll{
selectFooterLabel = it.hasProperty("footerLabel") ? it.getProperty("footerLabel").getString() : ""
}
In my jsp I'm just printing the property:
<%=selectFooterLabel%>
Thanks for the help!
findAll returns a List containing all the items in the original list for which the closure returns a Groovy-true value (boolean true, non-empty string/map/collection, non-null anything else). It looks like you probably wanted collect
def footerLabels = JcrUtils.getChildNodes("footer").collect{
it.hasProperty("footerLabel") ? it.getProperty("footerLabel").getString() : ""
}
which will give you a List of the values returned by the closure. If you then want only the subset of those that are not empty you can use findAll() with no closure parameter, which gives you the subset of values from the list that are themselves Groovy-true
def footerLabels = JcrUtils.getChildNodes("footer").collect{
it.hasProperty("footerLabel") ? it.getProperty("footerLabel").getString() : ""
}.findAll()

Resources