About take a variable from a array widget.

100 views
Skip to first unread message

maybeg...@gmail.com

unread,
Feb 7, 2014, 9:58:39 AM2/7/14
to suppor...@runmyprocess.com
Hi.

How can I express the first element of a array widget in JavaScript?

For example, if my array id is: "id_array", and the variable of the array is "array"..

Thanks

maybeg...@gmail.com

unread,
Feb 7, 2014, 10:09:19 AM2/7/14
to suppor...@runmyprocess.com, maybeg...@gmail.com
For example.

The column name is "User", How can I the first element of this column or the second element in javascript?.

Sabine El Rassy

unread,
Feb 7, 2014, 10:13:03 AM2/7/14
to RunMyProcess Support Forum

Hello, 


Let's say you have a widget array: 'id_array' with its variable 'variable_array'. Your array contains 1 column having 'array_column' as a name of variable.
In order to get the value of the first element in of the column 'array_column' of your array, you need to do as follow:

JSON.parse(RMPApplication.get("variable_array.array_column"))[0]

If you need the whole first row, you need to transpose the value of 
JSON.parse(RMPApplication.get("variable_array")) as the result within the array is by column and not by line.

Hope this was helpful,
Regards,

Sabine EL RASSY

maybeg...@gmail.com

unread,
Feb 7, 2014, 12:05:07 PM2/7/14
to suppor...@runmyprocess.com, maybeg...@gmail.com
Thank you so much Sabine!!!

One more thing,
Using:
JSON.parse(RMPApplication.get("variable_array"))

how could I create a pre launch script that compare all elements of the first column and if it finds a repeated element of the column, it shows a message like "I'm afraid that you have created a repeated one"

I appreciate it.

thoshino

unread,
Feb 7, 2014, 2:03:47 PM2/7/14
to suppor...@runmyprocess.com, maybeg...@gmail.com
Hi,

I found a Javascript in Stackoverflow  that might help you.

function find_duplicates(arr) {
  var len=arr.length,
      out=[],
      counts={};

  for (var i=0;i<len;i++) {
    var item = arr[i];
    var count = counts[item];
    counts[item] = counts[item] >= 1 ? counts[item] + 1 : 1;
  }

  for (var item in counts) {
    if(counts[item] > 1)
      out.push(item);
  }

  return out;
}

This function will return values that are duplicate.
So, in your pre-launch script, you can do something like this:

/*copy&paste the function above */

var user_duplicate = find_duplicates([[array.user]]);
if(user_duplicate == ""){
true;
}else {alert("your message")
};

You can even tell which users are duplicate in your alert like this:
alert("Error: following users are selected multiple times - " + user_duplicate);

In above example, array is the array variable, and user is the column variable. 

FYI: JSON.parse() that Sabine explained is incorporated in the JS function from Stackoverflow by multiple if's and for's. 
You can see how JSON.parse() is helpful and convenient - no need for that logic. This is the recommended way if you are dealing with data with your own code.

Best regards,

Taka

maybeg...@gmail.com

unread,
Feb 9, 2014, 11:26:31 AM2/9/14
to suppor...@runmyprocess.com, maybeg...@gmail.com
It works!!!


Thanks so much!
I'm so glad you could help me, a very detailed answer.

att:
Nes

Reply all
Reply to author
Forward
0 new messages