Focal Point
Allow users to enter multiple values for a field in a launch page

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

January 31, 2008, 09:55 AM
Jeff Elam
Allow users to enter multiple values for a field in a launch page
I have a requirement to allow users to enter (or ideally, paste) a list of values (10 or less) for a particular field, which will be used to filter a report. The values that the user would enter may or may not exist in the database, so I can't build a list for them to use to choose from the values--they need to enter them. Does anyone have a good method for accomplishing this? Users will be accessing an HTML page to launch their reports. Was trying to use the Text Area control--it lets me enter the text, but the report won't accept it as multiple rows of data. I could require the users to separate their values with a comma or semicolon, but that wouldn't be ideal. Even so, don't know how to tell WebFOCUS that those are individual, delimited values, rather than just a long string that happens to have semicolons or commas in it.


Jeff Elam
WF 8 in Windows
January 31, 2008, 10:03 AM
Anatess
Jeff, the text area may work in conjunction with the STRTOKEN function to split up the text with a delimiter.
We have done something where the users put the filters in a file (Excel in our case) and use that file as input to the fex.


WF 8.1.05 Windows
January 31, 2008, 10:25 AM
Jeff Elam
Thanks for the suggestion. I'm not familiar with the STRTOKEN expression. It looks like it's related to Maintain. Will that still work if I'm just trying split up a string to pass as individual values for a report?


Jeff Elam
WF 8 in Windows
January 31, 2008, 10:37 AM
Tony A
Jeff,

Not knowing what release, platform etc. you are on (see link on how to add these to your profile signature) or what experience of HTML and JavaScript you have, this can also be achieved within your launch page by using the JavaScript method "split".

What I use regularly is something like this (there is more involved but this sort of code is the basic part) -
function your_function() {
  parm_list = document.getElementById("textbox1");
  parm_array = parm_list.split(";");
  for (i=0; i<parm_array.length; i++) {
// Safety first check if exists and delete if necessary
    var RemCtrl = document.getElementById("parmvar"+i);
    if (RemCtrl) {
      document.form.removeChild(RemCtrl);
    }
    create_control("parmvar"+i,"parmvar",parm_array[i]);
  }
}

// Create a new input control from the supplied values
function create_control(ctrl,name,value) {
   var NewCtrl = document.createElement("input");
   NewCtrl.setAttribute("id", ctrl);
   NewCtrl.setAttribute("name", name);
   NewCtrl.setAttribute("type", "hidden");
   NewCtrl.setAttribute("value", value);
   document.form.appendChild(NewCtrl);
}

This will create one or many hidden inputs of the same name attribute and when the form is submitted, WebFOCUS will create the usual variables (using this code) of &parmvar, &parmvar0, &parvar1 etc.
&parmvar0 will hold the number of parmvar variables and each occurence will be suffixed with an indice.
&parmvar always holds the same value as &parmvar1 if it exists.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
January 31, 2008, 10:41 AM
Tony A
Sorry, forgot to say that if your user entered "string1;string2;string3;string4" then the variables passed to your fex would be -

&parmvar = string1
&parmvar0 = 4
&parmvar1 = string1
&parmvar2 = string2
&parmvar3 = string3
&parmvar4 = string4

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
January 31, 2008, 11:14 AM
Jeff Elam
Thanks, Tony. I updated my signature, but after my first post. This looks like it might work. A little more coding than I had in mind, but...


Jeff Elam
WF 8 in Windows
January 31, 2008, 12:14 PM
Anatess
Jeff, STRTOKEN is a string function available in Reporting as well. You can look it up in Dev Studio help files.


WF 8.1.05 Windows
January 31, 2008, 04:35 PM
Jeff Elam
Thanks. I see the STRTOKEN in the help files. Do you have an example of a procedure using this method?


Jeff Elam
WF 8 in Windows
January 31, 2008, 05:03 PM
Alan B
I know STRTOKEN from Maintain, but never from reporting.

STRTOKEN is an item in the MNTUWS subroutine library, specifically for maintain.


Alan.
WF 7.705/8.007
February 01, 2008, 07:19 AM
Jeff Elam
Tony, would you happen to have a relatively simple example of an HTML page and the FEX that it goes with? I think I understand how to use the Javascript, but am not sure how to make use of it. Thanks, again, for you suggestions.


Jeff Elam
WF 8 in Windows
February 01, 2008, 10:11 AM
Tony A
Jeff,

I am off today (so why am I posting? - sad boy Smiler) but I will try and knock a quick sample up for you. It won't have all the IBI js modules in the HTML so it will be concise and, hopefully, easier to understand.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 01, 2008, 10:24 AM
Jeff Elam
Thank you very much, Tony!


Jeff Elam
WF 8 in Windows
February 01, 2008, 11:53 AM
Darin Lee
Not being a javascript guru (although I DID copy Tony's code for later use), we accomplish the same task using Dialogue Manager:

-IF &ASSO_CD OMITS ';' GOTO ASO_LOOP;
-SET &ASSO_CD0=GETTOK(&MU_ASSO_CD,&MU_ASSO_CD.LENGTH,1,';',3,'A3');
-SET &ASO_TOK=2;
-SET &ASO_CNT=1;
-SET &ASO_IND=&ASSO_CD0;
-REPEAT ASO_LOOP WHILE &ASO_CNT LE &ASSO_CD0;
-SET &ASSO_CD&ASO_CNT.EVAL=GETTOK(&MU_ASSO_CD,&MU_ASSO_CD.LENGTH,&ASO_TOK,';',3,'A3');
-SET &ASO_TOK=&ASO_TOK + 1;
-SET &ASO_CNT=&ASO_CNT + 1;
-ASO_LOOP

The user enters values separated by ; In this case all values are three characters, thus, the A3. This could be parameterized as well if the values are variable length.

BTW: ASSO would be short for association. Haven't come up with a "nice" abbreviation for that one. Smiler Makes for interesting developer discussions.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
February 01, 2008, 12:03 PM
GinnyJakes
How about ASSN. I think that one is fairly common.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
February 01, 2008, 02:14 PM
Jeff Elam
Interesting idea using dialogue manager. If dialogue manager could recognize the carriage return, maybe I could allow users to paste them in from Excel or something. I'm probably reaching.


Jeff Elam
WF 8 in Windows
February 01, 2008, 04:01 PM
Alan B
Unfortunately WF strips out the carriage returns. Somewhere I have a small piece of js (1 line I think) that can replace the CR with another character which can then be used by DM to break the string.


Alan.
WF 7.705/8.007
February 01, 2008, 04:02 PM
Anatess
AH!!! My bad. I meant GETTOK not STRTOKEN. And Darin gave the example code up there. See, I need to work harder for that Platinum karma. Anyways, if your users would need to put it in an Excel anyway, might as well use an Excel File as an input into the fex.


WF 8.1.05 Windows
February 01, 2008, 04:16 PM
Tony A
Alan,

You mean this, or something like it -

' Change linefeeds to HTML breaks
  Comment=Replace(Comment,vbcrlf,"<br>")

Although this is VBscript as opposed to JavaScript and I use it within ASP code.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 01, 2008, 04:45 PM
Jeff Elam
Thank you very much! I'll give it a shot.

Jeff


Jeff Elam
WF 8 in Windows
February 01, 2008, 04:45 PM
Tony A
Jeff,

Sample HTML file -
<html>
<head>
<title>Parameter STring Parsing</title>
<script language=JavaScript>
function your_function() {
  parm_list = document.getElementById("textbox1").value;
  parm_array = parm_list.split(";");
  for (i=0; i<parm_array.length; i++) {
// Safety first check if exists and delete if necessary
    var RemCtrl = document.getElementById("parmvar"+i);
    if (RemCtrl) {
      document.form.removeChild(RemCtrl);
    }
    create_control("parmvar"+i,"parmvar",parm_array[i]);
  }
}

// Create a new input control from the supplied values
function create_control(ctrl,name,value) {
   var NewCtrl = document.createElement("input");
   NewCtrl.setAttribute("id", ctrl);
   NewCtrl.setAttribute("name", name);
   NewCtrl.setAttribute("type", "hidden");
   NewCtrl.setAttribute("value", value);
   document.form.appendChild(NewCtrl);
}
</script>
</head>
<body>
<form name="form" onsubmit="your_function();" method="get" action="/ibi_apps/WFServlet" target="_blank">
<input type="hidden" name="IBIAPP_app" id="IBIAPP_app" value="focalpoint">
<input type="hidden" name="IBIF_ex" id="IBIF_ex" value="parm_string.fex">
Enter your parms delimited by semi-colons:
<input type="text" id="textbox1" style="width:450px;" value="string1;string2;string3;string4">
<input type="submit" value="Run Report">
</form>
</body>
</html>

and the fex that it calls (very basic) -
-* File parm_String.fex
-SET &ECHO = ON;
-DEFAULT &parmvar = ''
-SET &T = '(''&parmvar.EVAL''';
-IF &parmvar0.EXISTS NE 1 THEN GOTO OUTLOOP1;
-REPEAT OUTLOOP1 FOR &COUNTER FROM 2 TO &parmvar0;
-SET &parmvarNEU = &parmvar.&COUNTER;
-SET &T = &T | ',''&parmvarNEU.EVAL''';
-OUTLOOP1
-SET &T = &T | ')';
-DONE

-TYPE &T.EVAL

T

p.s. Darin, note a slight mistake in the first function in the original JS Wink



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 01, 2008, 05:03 PM
Alan B
Thank you Tony, that's about it.

In js I get:
document.getElementById("textareaId").value=document.getElementById("textareaId").value.replace("%0D%0A","~")

and use the '~' in DM to split the items.


Alan.
WF 7.705/8.007
February 01, 2008, 06:25 PM
Darin Lee
I also use the ~ as the delimiter - doesn't get included in very many strings so the &VAR used in GETTOK is almost always parsed correctly.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
February 01, 2008, 10:13 PM
susannah
Jeff, download the manual "Using Functions" for version 76; its the shortest of the 4 manuals in the basic documentation set. And read the entire section on Text functions.
Focus has the coolest text unscrambling functions around. you can indeed recognize a carriage return. (or 'retour de charriot' as it says in french focus) Wink
or any character. look up HEXBYT, BYTVAL, and CTRAN. You'll copy and paste a carriage return character (mine show up as little boxes) into the BYTVAL function, extract its HEX value, and use that value in the CTRAN function to change it to a blank or a semi or whatever.
Focus text command are so strong you can take utter gibberish in and create poetry out.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
February 06, 2008, 08:59 AM
Jeff Elam
Tony, I've taken your JavaScript, but am trying to tackle both requirements at once. I'm using a textarea, and allowing the user to enter a value, hit return, and enter another value. This is what I've done:



Parameter STring Parsing
<script language=JavaScript>
function your_function() {

parm_list = document.getElementById("textarea1").value;
parm_array = parm_list.split("\n");
for (i=0; i// Safety first check if exists and delete if necessary
var RemCtrl = document.getElementById("parmvar"+i);
if (RemCtrl) {
document.form.removeChild(RemCtrl);
}
create_control("parmvar"+i,"parmvar",parm_array[i]);
}
}

The only real change was that I'm trying to use the "\n" to split at the carriage return, instead of having the user separate the data with semicolons. I've also changed the input type to a textarea, so it will accept the hard returns. When I run the report, the form works. When I submit, I get this error.

I get this error: 0 ERROR AT OR NEAR LINE 28 IN PROCEDURE _parm_stringFOCEXE
(FOC257) MISSING QUOTE MARKS: '45202 ; | 'IBIAPP_

The strange thing is, that if I clear out the Textarea, and run the report again, it runs. I wonder if it's having trouble accepting the data separated by carriage returns, even though I'm not using them?

Am I being overambitious, trying to do this in one step? Thanks, again, for all of your help.

This message has been edited. Last edited by: Jeff Elam,


Jeff Elam
WF 8 in Windows
February 06, 2008, 09:37 AM
Tony A
Jeff,

When ever you enter HTML into your post then your should put [ code] before it and [/code] after it, otherwise you get the HTML interpretted by the viewers browser.

Please edit your post above so that I can read your code without squinting at the page source Wink

To answer your last question, yes I think you may be being over ambitious if you do not know JS very much nor HTML and the DOM. We can assist you with the coding but you have to ask yourself the most important question -

Are your App Support people (or whom ever will support this code) within your Company, able to provide adequate support to your end result?

If the answer is no then I do not suggest that you attempt to put this into your code until the local support in capable.

T

This message has been edited. Last edited by: Tony A,



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 06, 2008, 09:45 AM
Tony A
BTW, read Alan's post above for a pointer.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 06, 2008, 10:09 AM
GamP
Jeff,

Took your code and ran it and found I had the same problem.
First I thought that it was because the textarea1 will also be sent out to WF, and that still contains \n's. So I had the textarea1 cleared. That did not help, strange enough.
The next funny thing is, that when I changed the 'hidden' attribute to 'text' the problem went away. So now the only thing left is to craete the new fields as visible fields and immediately hide them again.
The following piece of js does just that:
<html>
<head>
<title>Parameter STring Parsing</title>
<script language=JavaScript>
function your_function() {
  parm_list = document.getElementById("textarea1").value;
  parm_array = parm_list.split("\n");
  for (i=0; i<parm_array.length; i++) {
// Safety first check if exists and delete if necessary
    var RemCtrl = document.getElementById("parmvar"+i);
    if (RemCtrl) {
      document.form.removeChild(RemCtrl);
    }
    create_control("parmvar"+i,"parmvar"+i,parm_array[i]);
  }
  document.getElementById("textarea1").value = '';
}
function create_control(ctrl,name,value) {
   var NewCtrl = document.createElement("input");
   NewCtrl.setAttribute("id", ctrl);
   NewCtrl.setAttribute("name", name);
   NewCtrl.setAttribute("type", "text");
   NewCtrl.setAttribute("value", value);
   document.form.appendChild(NewCtrl);
   NewCtrl.style.display = 'none';
}
</script>
</head>
<body>
Enter your parms separated by returns:
<br>
<form name="form" onsubmit="your_function();" method="get" action="/ibi_apps/WFServlet" target="_blank">
<input type="hidden" name="IBIAPP_app" id="IBIAPP_app" value="session">
<input type="hidden" name="IBIF_ex" id="IBIF_ex" value="parm.fex">
Enter your parms delimited by semi-colons:
<TEXTAREA name="textarea1" rows="10" cols="10">
</TEXTAREA><br><br>
<input type="submit" value="Run Report">
</form>
</body>
</html>

In parm.fex I have only a -? &, to show which variables I have avialable in the procedure.

Hope this helps, it certainly taught me something...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
February 06, 2008, 10:19 AM
Alan B
Jeff

I made a mistake in my original post, so to rectify, I have put Tony's code and the correct split together:
<html>
<head>
<title>Parameter String Parsing</title>
<script language=JavaScript>
function your_function() {
  parm_list = document.getElementById("textarea1").value;

  parm_array = parm_list.split("\r\n");
  for (i=0; i<parm_array.length; i++) {
    var RemCtrl = document.getElementById("parmvar"+i);
    if (RemCtrl) {
      document.form.removeChild(RemCtrl);
    }
    create_control("parmvar"+i,"parmvar",parm_array[i]);
  }
}

function create_control(ctrl,name,value) {
alert(ctrl)
   var NewCtrl = document.createElement("input");
   NewCtrl.setAttribute("id", ctrl);
   NewCtrl.setAttribute("name", ctrl);
   NewCtrl.setAttribute("type", "hidden");
   NewCtrl.setAttribute("value", value);
   document.form.appendChild(NewCtrl);
}
</script>
</head>
<body>
<form name="form" onsubmit="your_function();" method="get" action="/ibi_apps/WFServlet" target="_blank">
<input type="hidden" name="IBIAPP_app" id="IBIAPP_app" value="TESTS">
<input type="hidden" name="IBIF_ex" id="IBIF_ex" value="parm_string.fex">
Enter your parms delimited by semi-colons:
<textarea name="textarea1" id="textarea1" rows="10" cols="10">
</textarea>
<input type="submit" value="Run Report">
</form>
</body>
</html>


The parms should be available as in Tony's fex code as parmvar0 - parmvarnn. Try this code to get the idea of what is going on. (I also changed the setAttribute of name to use ctrl, not name).


Alan.
WF 7.705/8.007
February 06, 2008, 11:03 AM
Tony A
Alan,

The passing of "name" in the create_control function is purposeful and the distinct variables will be created by WF. If you change it to use "ctrl" then you may not get the "parmvar0" set properly to the count of the variables.

For Jeff's information, the variable(s) produced by this JS would all be called "parmvar". WF encounters more that one value for parmvar and creates an "array" and then creates an additional variable suffixed with "0" (zero) with the count of the incoming variables. If the variable names were changed by using "ctrl" value instead, then the variables passed to WF would be parmvar1, parmvar2, parmvar3 etc. and no parmvar0.

Hope that helps with the reasoning.

T

This message has been edited. Last edited by: Tony A,



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 06, 2008, 12:10 PM
Alan B
Yes Tony, you are correct. I meant to say 'for testing I had changed name to ctrl so that I could pick up better in the URL', not that this was the way to go.


Alan.
WF 7.705/8.007