Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Changing value of row in Dataset using script in onFetch
chavez_ant
Hello,
I have several reports where I'd like to change a numeric value, based on the value of a Global variable. It seems faster to use this method, instead of modifying the sql for every report.
I'd like to use scripting in the onFetch method for this. Something like the following example. Let's say the report has a numeric COLUMN1 of counts that we don't want to display any values less than 6 (global variable Var is set to 6 previously in the report). If less than or equal to 6, the dataset changes the value to 6, otherwise the value displays in report.
if( row["COLUMN1"] <= reportContext.getGlobalVariable("Var") )
{
row["COLUMN1"] == null;
}
When I attempt a script like to above, report runs and still displays the field when the criteria has been met. I know I'm missing something here.
I'd appreciate any tips!
Thanks,
A.C.
Find more posts tagged with
Comments
mwilliams
Wait, so if it's less than your specified minimum value, you want to change it to the minimum value or you want to make it null? Also, where do you get this minimum value? How is that decided?
chavez_ant
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="80051" data-time="1310588311" data-date="13 July 2011 - 01:18 PM"><p>
Wait, so if it's less than your specified minimum value, you want to change it to the minimum value or you want to make it null? Also, where do you get this minimum value? How is that decided?<br /></p></blockquote>
<br />
mwilliams,<br />
<br />
Thanks for the reply!<br />
<br />
I do want to make the value in the dataset equal to null if it's lower than the minimum value. Even if we take the global variable out of the equation and I put into onFetch:<br />
<br />
if( row["COLUMN1"] <= 100 )<br />
{<br />
row["COLUMN1"] == null;<br />
}<br />
<br />
The value still does not null. I know I don't have the syntax correct, would like some assistance. FYI, We don't want to use the 'hide' feature because users could then export the data only, we don't want them to see it when it meets this criteria.<br />
<br />
To answer your other question, I'm setting the global variable in another dataset under onFetch, using: reportContext.setGlobalVariable("Val", row["LIMITVAL"])<br />
<br />
--A.C.
chavez_ant
I thought I'd check on this request. In the interim I'm going the route where I alter the query itself, scripting in the openMethod of the dataset. It does seem the above method I had tried would be faster, let me know if any can assist, as I'd prefer a method closer to the one described above.
Also, if cannot be done in javascript, would it be possible to do similar function in a java event handler?
Thanks again, in advance
mwilliams
I've never tried to change the value of the binding in the onFetch method. Would adding a computed column work for you? You could then use that column in your report instead.
chavez_ant
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="80274" data-time="1311112811" data-date="19 July 2011 - 03:00 PM"><p>
I've never tried to change the value of the binding in the onFetch method. Would adding a computed column work for you? You could then use that column in your report instead.<br /></p></blockquote>
<br />
That could work, but only if there's a way to block the original column that the first column was derived from, from being viewed or exported in the report. Is there a way to set a column in the dataset as hidden so it's not seen anywhere in report or in any form of exported data (not even in the 'export data only' option)<br />
<br />
Also let me know if you think it's worth my investigating further doing such functions with a Java handler.<br />
<br />
Thanks again, you and this forum always points me in the right direction.
mwilliams
When you "export data", you can choose any binding in the report. I don't think dataSets are available, just report elements. So, if you create a computed column in the dataSet, you can go to the binding tab of the element that uses this dataSet and remove the old binding that you don't want to be exported and it shouldn't be available. Check it out and let me know.
chavez_ant
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="80351" data-time="1311197861" data-date="20 July 2011 - 02:37 PM"><p>
When you "export data", you can choose any binding in the report. I don't think dataSets are available, just report elements. So, if you create a computed column in the dataSet, you can go to the binding tab of the element that uses this dataSet and remove the old binding that you don't want to be exported and it shouldn't be available. Check it out and let me know.<br /></p></blockquote>
<br />
Great tip, you're right, just need to remove the bindings for the non-computed fields with the values we don't want users to see. I just may go that route and let you know if any followup required to this question. thanks again.