Discussions
Categories
Choose a Product
THRUST SERVICES
CORE APPS
CE PRODUCTS
...
Quick Links
POPULAR
HELPFUL TIPS
Groups
My Links
FOR SIGNED IN MEMBERS:
Back to website
Home
Designing Analytics Reports
Javascript variable scope issue
Migrateduser
<p>I'm having an issue with some javascript I'm using. I'm declaring some variables and functions in initialize, building the array using those (global, right?) functions in initialize and then calling a function in afterFactory that sorts the array and stores it in another array variable. I know the function is working properly because I can log the array elements from afterFactory and everything is how I would expect it, but then when I try to access the arrays with a dynamic text box in the report, the sorted array is empty and the original array (which is global and has had all the elements removed by the function) is still full.<br />
<br />
I'm suspecting that BIRT handles variable scope in a way that I don't fully understand, because the original array that's built in onFetch has no problems being accessed by the report, just the array that's being changed in afterFactory isn't keeping the changed elements.<br />
<br />
Here's the JS I have in the different sections. Thanks.<br />
<br />
<span class='bbc_underline'><strong>Initialize</strong></span><br />
</p><div>var med_array = [];</div><div>//var sorted_array = [];</div><div>var final_array = [];</div><div>var test_array = [];</div><div>var janChange = "";</div><div>var test = 2;</div><div> </div><div>function Medication(name, start_date, stop_date, modified_date, strength, row_num){</div><div> this.name = name;</div><div> this.start_date = start_date;</div><div> this.stop_date = stop_date;</div><div> this.modified_date = modified_date;</div><div> this.strength = strength;</div><div> this.row_num = row_num;</div><div>}</div><div> </div><div>function sort_array(unsorted_array){</div><div> var groupNum = -1;</div><div> var sorted_array = [];</div><div> while(unsorted_array.length > 0){</div><div> if(unsorted_array[0].row_num == 1){</div><div> groupNum++;</div><div> sorted_array[groupNum] = [];</div><div> }</div><div> sorted_array[groupNum].push(unsorted_array.shift());</div><div>}</div><div> </div><div>return sorted_array;</div><div>}</div><p> </p><p><strong><span class='bbc_underline'>onFetch</span></strong><br />
<br />
med_array.push( new Medication(row["MEDICATION"], row["DATEPRESCRIBED"], row["DATESTOPPED"], row["LAST_MODIFIED"], row["DOSAGE"], row["ROW_NUM"]));</p><p> </p><p><strong><span class='bbc_underline'>afterFactory</span></strong></p><p> </p><p>final_array = sort_array(med_array);<br />
<br />
<span class='bbc_underline'><strong>BIRT Report dynamic text box</strong></span></p><p> </p><p>"Test" + " " + final_array[0] + " " + med_array[0] + " " + test<br />
<br />
</p>
Find more posts tagged with
Comments
There are no comments yet