The CreatorCon Call for Content is officially open! Get started here.

How to create variables from array's?

CPKIII
Tera Expert

I am sure I am missing something simple here.   I have a query to a table that looks like below.

var sys = "87b4b72c3869310001a8fa55d9ddeb4b";

var bud = new GlideRecord('u_demand_budget');

bud.addQuery('u_demand.sys_id',sys);

bud.query();

while(bud.next()){

var list = bud.u_fiscal_year.toString();

var fy = list.split("|");

for (var i=0; i < fy.length ; i++) {

gs.print(fy[i]);

}

}

The Print looks like this.  

*** Script: FY17

*** Script: FY18

*** Script: FY18

*** Script: FY16

How to get each return to be it's own variable.   IE:

var fy[1] = FY17

var fy[2] = FY18

Again I am sure there is something simple I am missing.   Any help is appreciated.  

1 ACCEPTED SOLUTION

First of all, you need to loop through the whole array like you are doing when you print out the array. Secondly, the parseFloat won't parse past the commas because they are special characters. So it parses up to the special character, like the quote said that I sent you before. So you have to take those out. Here is what the code should look like:



for (var i=0; i < opex.length; i++) {


gs.print("Opex " + opex[i]);


topex += parseFloat(opex[i].replace(/,/g, '').substr(1));


}



All of this is assuming that the string will come through in the same way each time: with a $ at the front and commas in it.


And it would be best to declare topex at the top of your script, like you have done with your other variables.



That should do it! Will you let me know how it worked?


View solution in original post

10 REPLIES 10

Thank You... I will try this out, and let you know how it goes.