Page 1 of 1

Hidden input textbox in JS not returning value to RPG

Posted: Mon Aug 24, 2020 7:38 pm
by marcpassmoor
To Whom It May Concern,

I have written a function, "getGridSortProperties", that it being performed within the OnSubmit of the CTL record format.
It correctly returns a structured return value containing 3 values; a Column List, an Order List, and a Direction List.
I am attempting to return the "GridSortProperties" for 2 grids; SFLC80 and SFLC20.
I defined, in the Visual Designer, 6 textbox elements with input CSS and named them; C80COLLIST, C80ORDLIST etc. as seen below.
The values appear to be correctly assigned via pui.set because I later reference them in the alert keyword.

let C80Lists = getGridSortProperties('SFLC80');
pui.set("C80COLLIST",C80Lists.sortColList);
pui.set("C80ORDLIST",C80Lists.sortOrdList);
pui.set("C80DIRLIST",C80Lists.sortDirList);
let C20Lists = getGridSortProperties('SFLC20');
pui.set("C20COLLIST",C20Lists.sortColList);
pui.set("C20ORDLIST",C20Lists.sortOrdList);
pui.set("C20DIRLIST",C20Lists.sortDirList);
if (C80Lists.sortColList != ""
|| C20Lists.sortColList != "") {
alert(
'Grid SFLC80'
+ '\nColumn List: ' + getElementValue("C80COLLIST")
+ '\nOrder List: ' + getElementValue("C80ORDLIST")
+ '\nDirection List: ' + getElementValue("C80DIRLIST")
+ '\n'
+ '\nGrid SFLC20'
+ '\nColumn List: ' + getElementValue("C20COLLIST")
+ '\nOrder List: ' + getElementValue("C20ORDLIST")
+ '\nDirection List: ' + getElementValue("C20DIRLIST")
);
};

However, when the CTL record format in which these 6 DIV textbox elements reside is read in by the RPG program the values in the returned data structure for these elements are blank. Am I missing something?

The purpose of the function is to allow client-side sorting to be performed (by NOT specifying the column sort response/field name sort response property and NOT the specifying return sort order property) but still pass back the response information to the RPG program so it can perform any task where that information would be useful.

Regards,
Marc Passmoor

Revolos

Re: Hidden input textbox in JS not returning value to RPG

Posted: Mon Aug 24, 2020 10:44 pm
by Scott Klement
You're doing this in the onsubmit event? The problem with that is that the response to send to the IBM i has already been determned before onsubmit is called. Therefore, calling pui.set() in onsubmit won't make any difference.

If you want to do this from the onsubmit event, you'll have to change it in the response object directly. If onsubmit is a function (rather than code typed into the 'onsubmit' field) it will be passed a parameter with this response object, you can then set the values therein.

There's an example of changing data in the onsubmit event here... take a look at the last example on this page where it clears the SEARCHDATA field:
https://docs.profoundlogic.com/display/ ... bmit+event

Note that when you change it in the onsubmit event like the above example, you must use the record format and bound variable names in uppercase. (This is different from the widget ids that pui.set() uses.)

Re: Hidden input textbox in JS not returning value to RPG

Posted: Tue Aug 25, 2020 10:27 am
by marcpassmoor
Thank you so much Scott. Your response was clear and allowed me to successfully implement my enhancement.
How the relevant response fields are updated from the OnSubmit event is shown below.
The values are now available in the RPG program.

All of the following is coded within the OnSubmit event of the CTL record format:

...existing GetGridSortProperties function

// new response code follows
function setResponse(response) {
response["CTL.C80COLLIST"] = C80Lists.sortColList;
response["CTL.C80ORDLIST"] = C80Lists.sortOrdList;
response["CTL.C80DIRLIST"] = C80Lists.sortDirList;
response["CTL.C20COLLIST"] = C20Lists.sortColList;
response["CTL.C20ORDLIST"] = C20Lists.sortOrdList;
response["CTL.C20DIRLIST"] = C20Lists.sortDirList;
};

let C80Lists = getGridSortProperties('SFLC80');
let C20Lists = getGridSortProperties('SFLC20');
setResponse;