Retrieving calculated string from program to web page

Started by pwhirley, May 15, 2024, 11:32:31 AM

Previous topic - Next topic

pwhirley

I'm not sure how best to explain my question. I feel sure it is an easy solution but I'm tired of trying to figure it out.
I have a file maintenance page generated through the NOMADS tools.  It works just fine and I've been able to do some tweaks.  I have copied _fm_webmaint to my progs folder and modified it and all the mods work except one.  One of the fields available to edit is the selected Printer.  I have made this a drop box and intend to offer a list of the available printers ON THE SERVER.  I inserted this line within the <form>:
[execute perform "Tools;Printer_List"]
The line executes and creates a variable, printerList$ that has a delimited list of available printers.  I cannot figure out how to make that variable available on the page so that it shows up in the line below:

[row "*\[show usefile field=printer$\]:"][list printer$ usefile event=Printer_Validate]
      [data rowsep=/]printerList$[/data][/list]
   [/row]<br />[/font][/font][/size][/size]

I have tried using %webster'Update(printerList$,mynewlist$) in my program, but I cannot get any data in the variable printerList$ on the web page.

Any help would be appreciated.  It is something simple, I am certain.

Thanks - Phil
Philip Whirley
Freelance software developer
Ride the Lowcountry, LLC
phil@whirley.org

Susan Cryderman

Hi Phil,

If I'm understanding this correctly - printer$ is the element in the data file being maintained and printerList$ is the delimited list of available printers (that is not an element in the data file).

I have not tried this - but it sounds like you might need to add a Hidden Variable to the form.  You can do this by adding a line using the [hide] short code to the generated html page that looks something like:

[hide printerList$ value=""]

- or -

If you are running PxPlus 2022 or later, you should be able to also do this from within the File Maintenance Generator.  Press the Hidden Variables button on Step 6 and add an Additional Variable of printerList$.

Susan Cryderman

Phil,

Just for clarification - you may NOT want to use the File Maintenance Generator method for adding the hidden variable as this would over-write the previous edits you made to the html file.

pwhirley

Thanks Susan,

Your understanding is correct.  I have tried adding a line down where all the other hidden variables are.  it looks like this:
[hide printerList$ value=""]

That didn't work, so I also tried adding printerList$ to the _fm_panel_iol$ value, also at the bottom of the page. 

Your suggestion suggests that I'm not totally ignorant, thankfully.  I think I understand this but I'm doing something wrong.

Phil
Philip Whirley
Freelance software developer
Ride the Lowcountry, LLC
phil@whirley.org

Susan Cryderman

Phil,

The difficulty here is that (I'm assuming) the list or printers needed is variable.  Because of this, the data needed for the drop box needs to be written to a memory file.

I tried the following and it seems to work (although I have not coded a Printer_Validate method).

1) Edited the _fm_panel_iol$ hidden variable in the html file to include printer$
2) Included the following code for the printer drop box:

[row "*\[show usefile field=printer$\]:"][list printer$ size=20 event=Printer_Validate program=c:\webster\prog\tools][/list][/row]<br>

3) Coded the c:\webster\prog/tools program to load a memory file as follows:

! tools - load printer list
!
  ENTER fileno
!
  OPEN (HFN)"*memory*"
  fileno=LFO
!
  printer_list$="Printer A/Printer B/Printer C/"
  FOR val$ FROM printer_list$
  WRITE (fileno,KEY=val$)
  NEXT
!
  EXIT 

You would need to edit your Printer_List method accordingly.

Hope this helps!

Mike King

Phil

There are any number of ways to add a printer list to a Webster+ panel.

If you have the list in a variable you can simply do something like:

[list printer$][data text=(printerlist$)][/list]

You can see this in the *webster/pages/reports.html file where the system loads variable fieldNames$ which was added to the form using a [hide] short code.  This variable was loaded in the [form program=*report] which runs the INIT event in *webster/report.


Personally though I wouldn't put the printer list in the form.  No need to have the system load it on every request.  On windows you can have a fairly significant delay to get the list of printers if some of them are offline or misconfigured.

Instead I would create a drop down query for a printer$ input field and set the field as 'required'.  Whenever printer$ input is changed I would have an event that updates the user data with the last requested printer using the %webster'SetUserData() method so that all subsequent requests will have %usr.Printer$ with the last selected printer.  You can then use an [exec printer$=%usr.printer$] in your logic to initialize the value.

There are other methods such as using cookies, but personally I would suggest using the user data as that would provides consistency for the user regardless as to the browser.

Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

pwhirley

Thanks Susan!
I ended up doing something similar to get around my problem.  I created a "printers.dat" table and a query.  I execute a routine to update the printers.dat and inserted a query lookup for the Printers field on my form. 
One thing I didn't understand in your example:  In the place where I would put the delimited list of drop-down options, you just execute your little program the *memory* file.  How does Webster+ know that the contents of the memory file are to be used for the options?  Does it just know that any *memory* file contains the options or is there some other secret. 

Thanks also, Mike!
The program isn't a report but a setup definition for an automatic printing routine which will run in background.  Part of the set up is to define which label printer is to be used, so I need to present a list of the valid printers, which might well change from one day to the next.  I do save the user's choice in the profile definition file, but when the user is creating the definition, she needs to see all the available printers.  I thought I could just put the printer list in a variable built in an executed routine and pass that variable back to the Webster+ web page.  That was not working.  I'll take a look at the reports.html and *report files to see if I can see what I was doing wrong.

Thanks for the help, both of you!

Phil
Philip Whirley
Freelance software developer
Ride the Lowcountry, LLC
phil@whirley.org

Mike King

#7
Phil

Perhaps this will help.  The following page shows a list of all printers configured on your Windows server (Windows only).  You can select one and press the button which will force a crash so you can see the values..

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>[ttl]Mike Printer Select[/ttl]</p>
<p>[form]
[execute winprt_setup read printer$]
[execute winprt_setup list printerlist$][hide printerlist$]
[list printer$ size=50/10][data text=(printerlist$)][/list]<hr>
[button text="Force Dump" event=crash@crash]
[/form]</p>
</body>
</html>


I used the [execute] to load the current/default printer and the full printer list.

BTW: The [hide] for the printerlist$ is not required but was included so you could see the values in the dump.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

pwhirley

This is helpful, Mike!  It did not occur to me to execute "winprt_setup" rather than executing a separate subroutine which then executes "winprt_setup".

I believe I'll implement this.

Phil
Philip Whirley
Freelance software developer
Ride the Lowcountry, LLC
phil@whirley.org

pwhirley

It also never occurred to me to [execute call "myroutine",mynewvariable$].   That is a very easy way to get individual variables back on to the web page dynamically. 
Lots of options.
- Phil
Philip Whirley
Freelance software developer
Ride the Lowcountry, LLC
phil@whirley.org

Mike King

When I was developing Webster+ I refined the logic and functionality based on the needs that came up in CATS demo application.

Once the basic design of Webster+ was done, I started with the demo application and as I ran into things that I felt could be done easier I added functionality to Webster+ and also worked with the development team to add functionality to the File Maintenance Generator to make application development faster and easier.

There are a lot of things that you can do in Webster+, many of which are incorporated in the Webster toolkit and the CATS demo application which is a good place to see what's possible.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com