Request to be able to extract args in array

variables
expression

#1

Hi,
It would be nice to be able to extract $args as array. For now I must know the args and specify it like: $args.name and it gives the value for name. We could also tell: arrayitem($index,$args.name) to loop throught multiple name value. But it would be awsome if we could tell: arrayitem($index,$args) so we could get the first arg directly. The best would be to match name and value to it.
For example: url?myname=paul&hisname=tom could be extract as: arrayitem(0,$args) as myname and then $args[arrayitem(0,$args)].[0] as paul.
This way we could iterate with for loop or something. With the setvariable() function we now can set variable by its name : setVariable("@"+varname,value) so I would like to set variable from url with single line of code but as soon as I have multiple variable it get complicated, I must send all name inside the name part and multiple value inside value part but as soon as the value is empty its not considered… Thanks


#2

Have you tried just using two variables?

string[] names
string[] values

names[0]=‘John’
values[0]=‘Doe’

execute piston “tester” with arguments {names, values}

Seems you could then iterate names, and values as a list, and do what you want with them

I have not tried a test program of this, but you could in webcore with sender and receiver and see if it works…

I still suggest you make this work first in webcore with a sender and a receiver, before playing with your external system. ie see the method works first.


#3

yes, I m doing that for now (name=john,ted,blabla & value=12,55,22,…) so I iterate each variable.But, if I wish to set variable to “” its impossible because it would not take empty string as an item… It s a mess because I have to built expressions to find out double coma to know its an empty item…
Inside the $args variable, its already shown as a kind of json like name:“name”,value:“value” but it looks like not possible to list it… what would be nice is to list those variable by their name but linked with their value, same way of local variable… so just by iterate you could have the name but the value also…
If it exist a way to increase this it would be nice!


#4

Also, if I could concatenate the $args I could iterate like this: $args.name+$index but I must enter $args.name2 I cannot add anything since its not considered as a part of the variable but the result + something. I keep trying to find a way to do it!
If you know a way to built the .name part it would be something! then I would use $args.name+$index so I could use: name0=bob&name1=ted&name2=rob&value0=22&value1=&value2=44 and this way it would accept empty value and I could end the loop on empty name value.
I could use multiple url with one name and value each but its anoying to repeat my code multiple time in my google script just for that!


#5

The best would be that when you use it as usual, no change but when you use it as array like: $args[0] it gives the first instance and by adding.name or .value it gives the first instance name and value… and change the 0 to other index…
It should be not to difficult to implement but don’t know where to ask the changes…


#6

if you are using list string,

you can have

[,,,]

which would be 3 empty values.


#7

I ll try that but it’s complicated because my data is separated with coma so I got some testing …


#8

I think I ll just iterate each variable ($args.name & $args.value) like: arrayitem($index,$args.name). It’s looks like working but I would limit the for loop to the array length but count($args.name) only count non empty value … is there a way to get the real length?


#9

did you look at size()?


#10

Wow, it’s working fine! Thanks!