Page 1 of 1

ONSELECT event not populating selectbox

Posted: Thu Dec 17, 2015 5:26 pm
by ppbedz
I have The following coded on the ONSELECT event for a database-driven auto-complete text box:
applyProperty("EquipSelect", "choices parameter value", get("VnnoSelect"));
applyProperty("EquipSelect", "field type", "select box");
applyProperty("MfgnoSelect", "choices parameter value", get("VnnoSelect"));
applyProperty("MfgnoSelect", "field type", "select box");

This is supposed to populate 2 select boxes. I know the event is executed because I added a pop-up after the last line to test. I also know that the sql that populates my select boxes based on the parameter from the text box DOES work. The problem is that the select boxes do not get populated unless I return control to my rpg pgm and redisplay the screen.

I have used this technique before and the select box was always populated immediately. The only difference is that my initiator was another select box with the javascript coded on the ONCHANGE event. So, I am guess the text box with the ONSELECT is somehow causing this not to work. I do not want to use a select box; I want the user to be able to zoom in on what they need. What do I need to do to make this code populate my select boxes immediately? Thank you, Patti
Here is the code from one of my select boxes:

Re: ONSELECT event not populating selectbox

Posted: Fri Dec 18, 2015 10:38 am
by Scott Klement
I don't see any reason why it'd matter if it's an 'onselect' event?!

Have you looked at the 'network' tab in your browser''s developer tools to see what is being sent/received to IBM i? Have you looked at PUISSNVP to make sure the SQL statement is correct? Have you looked at the job log for the SQL job to make sure there are no errors?

Re: ONSELECT event not populating selectbox

Posted: Mon Dec 21, 2015 9:38 am
by ppbedz
Scott,

I have not been able to see anything wrong. The sql returns the correct data when the screen redisplays (after control returns to pgm). I am enclosing the entire display file source. If you have a chance, can you take a look? Thank you and have a nice Holiday!!!! Patti

Re: ONSELECT event not populating selectbox

Posted: Mon Dec 21, 2015 12:55 pm
by Scott Klement
The problem is that your textbox ("VnnoSelect") has database-driven autocomplete enabled. This changes the html 'value' property (which is what you see on the screen for that widget) to be the vendor name rather than the vendor number.

From our conversation at RPG & DB2 Summit, it sounded like you wanted to learn how to debug this stuff yourself. For that reason, I'm going to spend some time explaining how I went about finding the problem.

First of all, because I don't have access to your system, I had to do some extra work that wouldn't be necessary for you:

1) Your DDS was sent as an SEU printout (rather than sending the actual code directly), so I had to first strip off the headings/footers, and remove the other superfluous bits (sequence numbers on the left, dates on the right, form feeds, etc) so I could load it into a regular DDS member.

2) Compiled the display file

3) Looked at your properties and saw which files/fields were used and created some compatable physical files.

4) Put some test data into the PFs from the last step.

5) Created an RPG program to display the record.

Once I had done all of that, I could reproduce the problem. When I run it, the dropdowns are blank. When I type a new vendor number in the VnnoSelect textbox, they remain blank. Now I'm at the same point that you're at. Here's what I did to troubleshoot it:

1) With the display on my screen, I looked at the PUISSNVP file. The SQL statements start in column 167 of the file, though I can scroll leftto see the widget information, session id, and scroll right to see the remainder of the SQL statement
puissnvp.png
puissnvp.png (33.49 KiB) Viewed 559 times

2) The SQL statements look fine, so I opened the browser's developer tools and went to the network tab. I'm using the Firebug developer tool in Firefox (though, both Chrome and IE also have good dev tools, you don't have to use Firebug, it's up to you.)

Since I knew it'd be making requests of the server any time I changed the vendor number field, I went ahead and did that and I saw requests made to the server to to PUI0009103 program. (I didn't need to know this program name in advance because I could clearly see the requests being made when I changed the vendor number, so it was clear that these were the right ones).

I expanded the 'response' information for these network requests:
firebug_response.png
firebug_response.png (110.76 KiB) Viewed 559 times
Hopefully you can see the error message is "Conversion error on variable or parameter". That seemed strange to me at first because the vendor number should be a value that can easily be converted to numeric. Maybe it's not sending what I expected for the vendor number?

3) I clicked on the "Post" tab in for these requests in my network tool. Post shows which data is being sent to the server. The "p1" variable will be the first parameter value. (If there were a 2nd parameter value it would be p2, etc.)
firebug_post.png
firebug_post.png (86.61 KiB) Viewed 559 times
Oops, here I can see that i"m not submitting the vendor number as originally thought, I'm submitting the vendor name! So now I went back and reviewed the display file and figured out what was happening... it was pretty clear, now, that it's because of the database-driven autoselect. (Though, maybe I should've thought of that earlier, I'm supposed to be an expert after all, but it didn't dawn on me until I saw the vendor name being submitted...)

Hope that this is helpful.

Re: ONSELECT event not populating selectbox

Posted: Mon Dec 21, 2015 1:47 pm
by ppbedz
Scott,

That is VERY helpful and I thank you for your time and explanation! Here is the gotcha... I want the vendor field to be data-base driven auto-complete in case the user does not know the vendor number (which "is" alpha even though we refer to it as "number"). Is there a way to keep the data-base driven auto complete with the vendor name and pass the "vendor number" to the sql?

Also, I apologize for the extra work with the SEU member. How should I save/send the next time?

Patti