Using a screen value as a host variable.

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
brianhd71
Profound User
Posts: 36
Joined: Thu Jan 02, 2014 6:20 pm
First Name: Brian
Last Name: Lannoye
Company Name: Dealertrack Technologies
Phone: 801.617.1806
State / Province: Utah
Zip / Postal Code: 84095
Country: United States
Contact:

Using a screen value as a host variable.

Post by brianhd71 »

I was wondering if there was a way to use a host variable in the Choices Selection Criteria property instead of having to go back to the RPG to get my values.

Every time do a pui.click(); to get a dynamic query, the page refreshes, all my select boxes clear out and it just looks clunky. I want to be able to search for data based on a screen value using only front end programming. Is there a script I can use or syntax for a host variable?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Using a screen value as a host variable.

Post by Scott Klement »

Choices selection criteria can have parameter markers. The parameter markers will work with the choices parameter value property, letting you specify a value in your display file.

For example, perhaps you only want to display rows where STATE='X' in your select box... but which state is shown will depend on what the user types in a "state" field, elsewhere on the display.

What you'd do in your properties is set these:

choices selection criteria: STATE=?
choices parameter value: script: pui,get("state")

These properties are evaluated when the dsplay loads, so when the display loads it gets the value of the "state" field on the display and puts it in the SQL statement used to load the select box.

But, when the user changes the "state" field, you want it to update th select box. So in the 'onchange' event for the state field, you put this:

applyProperty("mySelectBox", "choices parameter value", get(this));
applyProperty("mySelectBox", "field type", "select box');

Now when someoen changes the state field, it will trigger a change to the choices parameter value in the select box. re-applying the "field type" will make it re-run the SQL and repopulate the dropdown list. This is all done without doing pui.click or sending control back to RPG.
brianhd71
Profound User
Posts: 36
Joined: Thu Jan 02, 2014 6:20 pm
First Name: Brian
Last Name: Lannoye
Company Name: Dealertrack Technologies
Phone: 801.617.1806
State / Province: Utah
Zip / Postal Code: 84095
Country: United States
Contact:

Re: Using a screen value as a host variable.

Post by brianhd71 »

Thanks! That worked out well!
blakenielson1
New User
Posts: 9
Joined: Tue Aug 14, 2018 8:57 pm
First Name: Blake
Last Name: Nielson
Company Name: Revolos
City: Atlanta
State / Province: Georgia
Country: United States
Contact:

Re: Using a screen value as a host variable.

Post by blakenielson1 »

Scott is there a way to use the applyProperty in a updatable grid with a select box? It works great in a form, but I have not been able to replicate this functionality in a grid.
User avatar
Megan
Profound Logic Staff Member
Posts: 90
Joined: Mon Sep 11, 2017 12:15 pm
First Name: Megan
Last Name: Bond
Company Name: Profound Logic
Phone: 5623227473
State / Province: California
Zip / Postal Code: 92692
Country: United States
Contact:

Re: Using a screen value as a host variable.

Post by Megan »

Hello Blake,

When updating grid fields, are you adding the row number to the id of the widget? Because HTML IDs are expected to be unique to each element, they cannot be duplicated, unless you are intentionally overwriting an existing element. This can cause all kinds of display issues, though, so it is not suggested, there are better ways to handle such. Because of this, each row element has the row appended to the ID. For example, if I added a select box to a grid with ID "choiceBox", then the select box on the 7th row would have ID "choiceBox.7".

There are a variety of ways to get the correct element ID, depending on what event you are using to trigger the refresh of the select box choices. The basic format of "generating" the ID of a widget in a particular row in JavaScript:

Code: Select all

var choiceBoxID = "choiceBox." + fieldRow;
Where fieldRow would have the record number of the field as written to the grid/subfile. We do provided row information to events of grid elements in one or more of the following variables, depending on the event:

Code: Select all

row - contains the record number as written to the grid/subfile. (Intended to be fully deprecated at some point for most/all events.)

rrn - contains the record number as written to the grid/subfile. (Recent Profound UI releases only.)

rowNumber - contains the current ordered position of record after filters and sorts are applied. (Recent Profound UI releases only.)
For the element IDs, you'll want to use rrn if available to the event or row if it is not when generating field IDs of widgets in a grid that can be sorted or filtered in such a way that it would cause their grid position to be different from their record number, which would cause rowNumber to provide the wrong row in regards to what you are looking for.

I also have examples of parsing RRNs from the ID of an element, should you need to for some reason and row/rrn/rowNumber won't work, in my workspace here: https://noderun.com/ide/megan_bond/parse-rrn-from-id/.

The workspace can be forked and you would then be able to go through and uncomment the code in events of the widgets you would like to see the results of. They are currently uncommented so that they don't flood the browser console with messages. To view the browser console in modern browser, you can press Ctrl + Shift + I or Ctrl + Shift + J. Please note that IE is not a modern browser, F12 or the browser menu is instead needed to open the console.

More information on dynamic select boxes can be found here: https://blog.profoundlogic.com/profound ... tered-data.

I hope this helps!

Thanks,
~MEGAN BOND
Technical Support Specialist
support@profoundlogic.com
blakenielson1
New User
Posts: 9
Joined: Tue Aug 14, 2018 8:57 pm
First Name: Blake
Last Name: Nielson
Company Name: Revolos
City: Atlanta
State / Province: Georgia
Country: United States
Contact:

Re: Using a screen value as a host variable.

Post by blakenielson1 »

Megan,

Thanks so much this is exactly the info I needed to make this work I added the following code to my combo box and it works like a champ!
var fname = getObj("RTUPDATE_Grid").grid.getDataValue(row, "FILENAME");
rrnRowNum = getObj("RTUPDATE_Grid").grid.getRowNumber(rrn);
var fieldnameID = 'FIELDNAME' + '.' + rrnRowNum;
applyProperty(fieldnameID,'choices selection criteria',"FILENAME = ?");
applyProperty(fieldnameID,'choices parameter value',fname);
applyProperty(fieldnameID,'field type','select box');
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests