Dustjs-linkedin pass variable in nested loop - node.js

I am trying to pass a variable from the first loop into the next. Why am I doing this? Well they both have the same key. Here is an example of trying to pass the index from the first loop into the second. Both values end up being the $idx of the second loop. How can this be done?
{#first}
{#second firstIDX="{$idx}"}
{firstIDX} : {$idx}<br>
{/second}
{/first}

I managed to get this working using the following (dot notation and no quotes):
{#first}
{#second firstIDX=$idx firstID=._id}
{firstIDX} : {$idx}<br>
{firstID} : {_id}<br>
{/second}
{/first}

Related

How to write an expression that evaluates a pipeline parameter to TRUE/FALSE?

I have a pipeline parameter fed by a config file in SQL.
Sometimes that parameter will be empty, not NULL but just empty ('').
How do I write an expression that will evaluate the parameter to TRUE/FALSE(blank/not blank) that I can put into my IF activity?
Basic question but thanks a lot.
I tried
#pipeline().parameters.x = ''
but it just told me Parameter x = '' was not found .......
You can use the below expression in the if activity to evaluate a parameter is empty or not.
#empty(pipeline().parameters.ok)
Sample demonstration:
A sample parameter ok.
For example, purpose I have created a string variable which I will use inside if to check the output.
In if give the above expression.
Inside True activities I have given a set variable activity and gave some value and did the same inside false activities.
Output when the parameter value is not given(empty).
Output when we gave any value to the parameter

Py3o.template : How to increment py3o variable inside a loop?

I'm working on .odt report using py3o.template in Odoo. In the report, I need to add a number in a Group, so if I have 3 groups, It should print out : Group 1Group 2Group 3
I did it like in this image :
It doesn't work and I get these errors :
"Could not move siblings for '%s'" % py3o_base
py3o.template.main.TemplateException: Could not move siblings for
'with="i=1"'
Can you help me?
PS : I need to call "i" between Group and [date_start]
This error happens when you did not have close properly your tags.
I can see only one closing with, try to close the two others.
Check the following example:
with="index=1"
with="index=index+1"
with="index=index+1"
function="index" index=3
/with
function="index" index=2
/with
function="index" index=1
/with
function="index" index undefined
Note that if a variable of the same name already existed outside of the scope of the with directive, it will not be overwritten. Instead, it will have the same value it had prior to the with assignment. Effectively, this means that variables are immutable.
To avoid that we can use a list to hold indexes and in each iteration we will create a new variable to hold the new index (we can use list.pop(0) to remove the previous index).
with="index=[1]"
for="item in range(4)"
function="index[-1]"
with="_=index.append(index[-1]+1)"
/with
with="_=index.pop(0)"
/with
/for
At the end index = function="str(index)"
/with
The output should be:
1
2
3
4
At the end index == [5]
To enumerate the loop items I highly recommend using enumerate function.
for="index,d in enumerate(o.get_session_date_ids(), 1)"
function="index"

How to repeat a string 'x' amount of times in Livecode

I have a program which sets a variable "x" to the length of a random dictionary word, and then should put "a" into a field x amount of times. However I am unsure whether my syntax is right or wrong. The variable randomword is already defined and works. My non-working code is as follows:
global x
on mouseUp
put length(randomword) into x
put repeatedString("a",x) into field "wordDisplay"
end mouseUp
However, when I look at wordDisplay after clicking my button, it is blank. An explanation of why, and code to fix this would be really beneficial.
Cheers.
You don't say if 'repeatedString' is a function you're calling from somewhere else, but if I understand what you're trying to do, you can try something like this, where you place 'a' into temporary variable:
put length(randomword) into x
repeat x
put "a" after temp
end repeat
set text of field "wordDisplay" to temp
Also, am guessing this is the case, but the only reason to use the global is if you plan to use the value of x across the scripts of multiple objects. If you're just using 'x' in this script, you don't need the variable declaration.
Page 227 of my book "Programming LiveCode for the Real Beginner" contains the following useful function, which does exactly what you want:
function repeatChar theChar,theAmount
local myLongString
set the itemDel to theChar
put theChar into item theAmount of myLongString
return myLongString
end repeatChar
Note that a repeat loop is not necessary.
Use the function in your script like this:
global randomWord
on mouseUp
local x
put length(randomWord) into x
put repeatChar("a",x) into field "wordDisplay"
end mouseUp

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()

How do I use a value in a loop outside of the loop?

I asked another question that wasnt answered, which led me to this question. I have a for loop that makes an array of the samples in a sound file. I do it to two files, and try to combine them in a third file. However, the array of values only exists within the for loop so I can't use the values I need in the third because to I need to access the array of samples in the third file using a for loop as well. A nested for loop doesnt seem to make sense in this situation.
Sorry forgot to mention I'm using python.
This is the chunk of the code that confuses me.
for index in getSamples(sound1):
v1 = getSampleValue(index)
for index in getSamples(sound2):
v2 = getSampleValue(index)
for index in getSamples(sound3):
setSampleValue(index, v1+v2)
So the code basically gets all the samples from sound1, all the samples from sound 2, and tries to set the samples in sound3(same length as both sounds) to the combination of each sample at each index.
However when this only plays/explores a blank sound for sound 3. I think the problem is that v1 and v2 are only equal to the values of the entire array within the individual for loops.
in order to use a variable outside of the loop to reference the array, you need to initialize that variable outside of the loops. This gives you a reference to the array.
var array = new Array();
for (int x=0; x<sample.length(); x++) {
//do stuff in the loop to 'array' variable
}
//do what you want with 'array' after the loop
Not sure what are you intend to do since you don't provide any chunks of code.
But basically, yes you can. I'll write something in php:
$myarray = array(); //init the array
for($i=1; $i<10; $i++){
//do something with myarray
}
//you can use myarray here
The point is : declare the "whatever you want to use" outside the loop before the loop started

Resources