View Full Version : retrieve optional parameters in HTML
ThierryC
01-11-2010, 09:30 AM
Hi,
is there a way to retrieve the optional parameters (as defined in Valence/administration/options) directly from within the HTML -code?
f.e i've defined with the option : fromyear=2009;
this parameter in known in the Rpg-program, but is there a way to make this parm also viewable directly from the HTML/javascript code ?
richard.milone
01-11-2010, 11:58 AM
This is a great question! Those optional parameters on the option master record are designed to "securely" control the mode or functionality of the RPG program on the back end and are inserted into the HTTP QUERY_STRING automatically by the VVCALL program. It is intentional that they cannot be overriden or otherwise passed in from the front-end for security reasons. Say for example you have an RPG program with a parameter that controls whether the program is in "inquiry" mode or "maintenance" mode. You can set up two options in Valence that have different "optional parameters" that call the exact same program. Having VVCALL insert those parameters eliminates the possibility that a smart user could hack the parameter and get into maintenance mode through the inquiry program. Now, with that said, you can get the values on the front-end but you would have to write in a standard AJAX call to one of your RPG programs authorized by that option to get the values and return them.
ThierryC
01-12-2010, 11:00 AM
Hi Richard,
thx for the reply but i'm still struggling with something of which i think is some basic of javascript.. i hope you can help me out with this.
The thing i'd like to achieve is to return the value of the optional parm in my Html.
as suggested by you, i've tried this by running an Ajax call to the rpg, which returns the value of the parameter requested back to the html.
The example below is the showing the problem, in the first field, when i enter the name of the param ('f.e frommonth') and i click 'GO' then the value is correctly set in the second field (response'),
however, i'd like the value already be there when the html is first shown.
i've tried this (the 3rd field : firstAjax) by running a function on the value parm of the 'firstAjax' field.
as the example is now defined: on the value parm of the 'firstAjax' i run the function 'function1', which runs perfectly.
however when defining 'function2' to be executed: as soon as i run the Ajax request, no value is shown anymore.. only the Setvalue works, but returning the value does not work. !!
is there a way to achieve this anyhow?
Ext.onReady(function() {
var function1 = function(parameter){
return parameter;
};
var function2= function(parameter) {
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {pgm: 'TESTEXT1', action: 'GetOptParm', variable: parameter},
success: function(response) {
//Ext.getCmp('firstAjax').setValue(response.response Text); --> this works
return ('response'); //--doesn't work
//return (response.responseText); //-- not ok
},
failure: function(response) {
return ('Failure');
}
});
}
// call an RPG program named EXFRMHW with an action of "sayHello"
var callRPG = function() {
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
pgm: 'TESTEXT1',
action: 'GetOptParm',
variable: Ext.getCmp('variable').getValue()
},
success: function(response) {
Ext.getCmp('response').setValue(response.responseT ext);
}
});
};
// define the form panel
var formMain = new Ext.FormPanel({
frame: true,
title: 'TESTEXT1',
labelAlign: 'right',
labelWidth: 175,
width: 475,
iconCls: 'application_view_detail',
items: [{
xtype: 'textfield',
id: 'variable',
fieldLabel: 'Enter variablename',
width: 200
}, {
xtype: 'textfield',
id: 'response',
fieldLabel: 'Response from RPG program',
readOnly: true,
width: 275
}, {
xtype: 'textfield',
id: 'firstAjax',
fieldLabel: 'Response from first Ajax Rqst',
readOnly: true,
value: function1('frommonth'),
width: 275
}
],
buttons: [{
text: 'Go',
id: 'buttonGo',
iconCls: 'accept',
handler: callRPG
}],
keys: [{
key: Ext.EventObject.ENTER,
fn: callRPG
}]
});
// render the form into the main document body
formMain.render('formMain');
// focus the cursor on the name field
Ext.getCmp('variable').focus();
});
</script>
richard.milone
01-12-2010, 01:59 PM
Hi ThierryC,
You're running into a classic asynchronous timing issue. Your code is attempting to display the value before the value has been successfully returned by the ajax call because JavaScript code execution does not pause and wait for a response. You need to use a technique where you call for the parameters on startup and then use a callback function to continue code execution.
Below I have reworked your code a bit. I took the Ext.onReady away from the first statement and just changed that to start a function called helloWorld. Now the program logic exists within that function that will get defined when the page is loaded but will not execute until you call it explicitly. You'll also notice a new code block at the bottom with Ext.onReady that fires off the ajax request for your startup parameters. The way I coded it assumes you will send back a simple JSON response with fields PARM1 and PARM2 but you can call them whatever you want of course. You would also need to send back a SUCCESS:1 in the JSON response. You see in that startup ajax call that if it's successful it will then call helloWorld and pass in the two parameters which you can then use within the helloWorld function anywhere you need.
This technique should work. If you have any problems implementing this technique let me know and I will help further.
var helloWorld = function(parm1, parm2) {
var callRPG = function() {
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
pgm: 'EXFRMHW',
action: 'sayHello',
name: Ext.getCmp('name').getValue()
},
success: function(response) {
Ext.getCmp('response').setValue(response.responseT ext);
}
});
};
// define the form panel
var formMain = new Ext.FormPanel({
frame: true,
title: 'TESTEXT1',
labelAlign: 'right',
labelWidth: 175,
width: 475,
iconCls: 'application_view_detail',
items: [{
xtype: 'textfield',
id: 'variable',
fieldLabel: 'Enter variablename',
width: 200
}, {
xtype: 'textfield',
id: 'response',
fieldLabel: 'Response from RPG program',
readOnly: true,
width: 275
}, {
xtype: 'textfield',
id: 'firstAjax',
fieldLabel: 'Response from first Ajax Rqst',
readOnly: true,
value: parm1,
width: 275
}],
buttons: [{
text: 'Go',
id: 'buttonGo',
iconCls: 'accept',
handler: callRPG
}],
keys: [{
key: Ext.EventObject.ENTER,
fn: callRPG
}]
});
// render the form into the main document body
formMain.render('formMain');
// focus the cursor on the name field
Ext.getCmp('variable').focus();
};
Ext.onReady(function() {
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
pgm: 'TESTEXT1',
action: 'GetOptParms'
},
success: function(response) {
var check = response.responseText;
if (check) {
var data = Ext.decode(response.responseText);
if (data.SUCCESS == '1') {
helloWorld(data.PARM1, data.PARM2);
}
}
},
failure: function(response) {
Ext.Msg.alert('Could not get startup values');
}
});
});
ThierryC
01-14-2010, 03:49 AM
Hi, Richard,
your solution indeed works fine....and is also clear to me now.
...i still need to get used to the idea that javascript acts different than rpg-code..
thx for your valuable contribution to the problem...
vBulletin® v3.7.1, Copyright ©2000-2010, Jelsoft Enterprises Ltd.