Focal Point
[CLOSED] Passing a random number in FOCEXEC

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/574103825

September 15, 2010, 03:39 PM
Priya
[CLOSED] Passing a random number in FOCEXEC
Hi,

I want to pass a random number in FOCEXEC of the parent that calls the child fex. This way every time the child is invoked from the parent,a different random number will be passed in the URL.

For example,
-SET &ACROSSCOLNAME = 'DUMMY';
-SET &TMPFORMAT = 'monthly';
-SET &METmetric1 = 'Peak_Volume';
-SET &FUNmetric1 = 'SUM';
-SET &PARFEX = 'r16489';
-SET &SERIES1WIDTH =1 ;
-SET &SERIES1TYPE =1 ;
-SET &SERIES1TYPE=1;
-SET &SERIES1AXIS=0;
-SET &RANDOM = RDUNIF('D4.3') * 100;
.
.
-* I am passing the above values in FOCEXEC to a child fex,

TYPE=DATA, ACROSSCOLUMN=metric1, COLOR=RGB(255 153 255),
FOCEXEC=&PARFEX(DATE_TIME=TIMECOL ACROSSCOL_NAME='&ACROSSCOLNAME'
ACROSSCOL_VAL=acrosscol COLNAME ='&METmetric1' FUNC ='&FUNmetric1'
FORMAT='&TMPFORMAT' ROUTETYPE='CHILD' TYPE='&SERIES1TYPE' RANDOM = '&RANDOM'
),TARGET=_blank, $
ENDSTYLE

But when the URL is passed with the paramters,the RANDOM value remains the same always. But I need something like this :
Every time I click on a bar, a link with different RANDOM numbers need to be generated.

Is there something that should be done with Javascript to overwrite the inital value,every time another action occurs.?

This message has been edited. Last edited by: Kerry,


769
Windows

Using all the above
September 15, 2010, 03:55 PM
<JG>
Correct Javascript, several examples on the forum.

As an easy alternative try using -SET &RAND=HHMMSS('A8'); in the focexec and pass that &RAND.

That will make it different for every run.
September 15, 2010, 04:50 PM
Priya
This does'nt work. When we SET a variable and then try to pass that variable in the FOCEXEC, the value does not change since the function does not get executed.


769
Windows

Using all the above
September 15, 2010, 05:44 PM
Waz
I assume that your parnet report does not get refreshed, therefore the & value of random does not get refreshed.

Javascript is the simplest way.

The question then is wich way, you could just create a form and populate the random value on submitting it.

You could also create a script that searched through your links and updates the value.

There are probably many other options as well.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

September 16, 2010, 01:16 PM
Priya
Can you please send me an example.?


769
Windows

Using all the above
September 16, 2010, 06:23 PM
Waz
Here is an example of updating the drilldown its self.

It is set to update every 10 seconds.

This will only work for HTML reports, and I've only tested with IE.

TABLE FILE CAR
PRINT COUNTRY
ON TABLE SET STYLE *
 TYPE=DATA, FOCEXEC=DRILL(RANDOM=''), $
ENDSTYLE
END

-RUN

-HTMLFORM BEGIN
<script language="JavaScript">
<!--
  function setRandom() {
    var anc_list = document.getElementsByTagName("A") ;
    for (var _c1=0;_c1<anc_list.length;_c1++) {
      var _bits = anc_list[_c1].href.toString().split('=') ;
      _bits[_bits.length-1] = new Date() ;
      anc_list[_c1].href = _bits.join('=') ;
    }
    alert(document.body.innerHTML) ;
    window.setTimeout('setRandom()',10000) ;
  }
  setRandom() ;
//-->
</script>
-HTMLFORM END



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

September 16, 2010, 10:13 PM
Doug
Hey Waz,

That sounds like something that can be added to an on_click event where "var" can be incremented and used in the drilldown code... I'll see if I can come up with something that does that. But, I'm off for the night. So, feel free to do it to it...

Doug
September 16, 2010, 10:54 PM
Waz
Hey Doug, that a good idea.

Here is my simple one.

TABLE FILE CAR
PRINT COUNTRY
ON TABLE SET STYLE *
 TYPE=DATA, FOCEXEC=DRILL(RANDOM=''), $
ENDSTYLE
END

-RUN

-HTMLFORM BEGIN
<script language="JavaScript">
<!--
  function setOnClick() {
    var anc_list = document.getElementsByTagName("A") ;
    for (var _c1=0;_c1<anc_list.length;_c1++) {
      anc_list[_c1].onclick = function() {setRandom(this);}
//      anc_list[_c1].onmouseover = function() {setRandom(this);}
    }
  }
  function setRandom(_anchor) {
    var _bits = _anchor.href.toString().split('=') ;
    _bits[_bits.length-1] = new Date() ;
    _anchor.href = _bits.join('=') ;
    alert(_anchor.href) ;
  }
  setOnClick() ;
//-->
</script>
-HTMLFORM END


You could also do it with an onmouseover event.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

September 20, 2010, 08:30 AM
Danny-SRL
One could also be "pure focus".
Calling fex:
  
-* File PassRandom.fex
DEFINE FILE CAR
RD/D3 WITH SALES=RDUNIF('D4.3') * 100;
END
TABLE FILE CAR
SUM SALES
FST.RD NOPRINT
BY COUNTRY
BY CAR
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
TYPE=DATA, COLUMN=SALES, FOCEXEC=GETRANDOM(COUNTRY=COUNTRY CAR=CAR RD=FST.RD), $
ENDSTYLE
END


Called Fex:
-* File GetRandom.fex
-TYPE COUNTRY=&COUNTRY
-TYPE CAR=&CAR
-TYPE RANDOM=&RD



Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

September 20, 2010, 02:47 PM
Priya
Hi,

Thanks for the response. The javascript code works fine for the tables. Upon clicking on the link, it takes me to the URL that has the random values poplualted. But this works fine only when we click on a link (href). What am I supposed to do to make this work in the graph. When a bar is clicked the URL is populated without the random value.

GRAPH FILE CAR
SUM SALES
ACROSS COUNTRY

ON GRAPH SET LOOKGRAPH VBAR
ON GRAPH SET 3D OFF
ON GRAPH SET BARNUMB OFF
ON GRAPH SET GRID ON
ON GRAPH SET GRAPHEDIT SERVER
ON GRAPH SET GRMERGE ON
ON GRAPH SET VZERO OFF

ON GRAPH SET STYLE *



TYPE=DATA,COLUMN=N1,FOCEXEC=TEST(RANDOM = ''), $


ENDSTYLE
END
-RUN
-HTMLFORM BEGIN

<script language="JavaScript">
function setRandom() {
var anc_list = document.getElementsByTagName("A") ;
for (var _c1=0;_c1 var _bits = anc_list[_c1].href.toString().split('=') ;
_bits[_bits.length-1] = new Date() ;
anc_list[_c1].href = _bits.join('=') ;
}
window.setTimeout('setRandom()',10000) ;
}

setRandom() ;

-HTMLFORM END

Thanks
Priya.


769
Windows

Using all the above
September 20, 2010, 04:43 PM
Francis Mariani
Try this:

-* File random4.fex

GRAPH FILE CAR
SUM SALES
ACROSS COUNTRY
BY BODYTYPE

ON GRAPH SET GRMERGE ON

ON GRAPH SET STYLE *
TYPE=DATA, JAVASCRIPT=runfex (COUNTRY BODYTYPE), $
ENDSTYLE
END
-RUN

-HTMLFORM BEGIN
<script type="text/javascript">

function runfex(country, bodytype)
{
random = Math.floor((Math.random()*100000));
url = 'WFServlet?&|IBIAPP_app=test&|IBIF_ex=RANDOM2&|COUNTRY=' + country + '&|BODYTYPE=' + bodytype + '&|RANDOM=' + random;

fexwindow = window.open(url, 'fexwindow');
fexwindow.focus();
}
</script>

-HTMLFORM END
-EXIT



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
September 20, 2010, 05:56 PM
Waz
As GRAPHEDIT SERVER creates an image and then mapps the drilldoes with the AREA tag, the change is simple.

GRAPH FILE CAR
SUM SALES
ACROSS COUNTRY

ON GRAPH SET LOOKGRAPH VBAR
ON GRAPH SET 3D OFF
ON GRAPH SET BARNUMB OFF
ON GRAPH SET GRID ON
ON GRAPH SET GRAPHEDIT SERVER
ON GRAPH SET GRMERGE ON
ON GRAPH SET VZERO OFF

ON GRAPH SET STYLE *



TYPE=DATA,COLUMN=N1,FOCEXEC=TEST(RANDOM = ''), $


ENDSTYLE
END
-RUN
-HTMLFORM BEGIN
<script language="JavaScript">
<!--
  function setRandom() {
    var anc_list = document.getElementsByTagName("AREA") ;
    for (var _c1=0;_c1<anc_list.length;_c1++) {
      var _bits = anc_list[_c1].href.toString().split('=') ;
      _bits[_bits.length-1] = new Date() ;
      anc_list[_c1].href = _bits.join('=') ;
    }
    alert(document.body.innerHTML) ;
    window.setTimeout('setRandom()',10000) ;
  }
  setRandom() ;
//-->
</script>
-HTMLFORM END



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!