Page 1 of 1

parm issue

Posted: Wed Jul 22, 2015 3:55 pm
by ppbedz
I am loading the contents of a select box from a data-base driven selection with a select statement that accepts 4 parms. The statement works properly if I omit the last 2 parms (which are date fields). It does not work if I include them. I am enclosing the "on change" code and data-base driven selection code. Can you help me make the selection work with all 4 parms? Thank you, Patti

Re: parm issue

Posted: Wed Jul 22, 2015 4:48 pm
by Scott Klement
The tricky thing about date fields in database-driven fields... the date must be in the format of YYYY-MM-DD (the *ISO format).

Since the code you're using to set the parameter values is JavaScript, the data will always be supplied as a character string. JavaScript does not have a "date type field" primitive like RPG does, so it'll always be a string. This is no problem, since SQL will automatically convert a string to a date if it's recognized in the date format.

I think our SQL-driven components always use the format YYYY-MM-DD. So if you can manipulate your date into that format, it should work.

Re: parm issue

Posted: Wed Jul 22, 2015 6:00 pm
by Scott Klement
For example, let's say you have a date field set up like this:
7-22-2015 4-54-46 PM.png
7-22-2015 4-54-46 PM.png (17.43 KiB) Viewed 353 times
Since this date field is configured to be in MM/DD/YY format (because that's what the user finds the most friendly for this example) the get("INVDAT") call for this field would also return a string in MM/DD/YY format. To make it work with SQL, we'll need to flip it around. So in your onchange event for the date field, you'd put code like this:

Code: Select all

// Date in INVDAT field is in MM/DD/YY format
//  but for the SQL we need YYYY-MM-DD format
//  so rearrange it here:
var datemdy = get("INVDAT");
var dateiso = "20" + datemdy.substr(6,2)
            +  "-" + datemdy.substr(0,2)
            +  "-" + datemdy.substr(3,2);

// set the parameter value and re-load the drop-down
applyProperty("mySelect", "parameter value 3", dateiso);
applyProperty("mySelect", "field type", "select box");
Of course, your date field might be a different format, and I know it had a different field name, etc... so you'll need to adjust the code accordingly, but hopefully this gets you pointed in the right direction.

Re: parm issue

Posted: Fri Jul 24, 2015 8:37 am
by ppbedz
test