Just in case someone else is struggling with the same thing as I've been struggling for a while, this explanation might save you some time and tufts of hair.
Task: Grid1 row calls Grid2, and Grid2 needs to know the primary key (row ID) of the calling row in Grid1.
First solution: Create a session variable during the call from Grid1, and store the primary key in that variable. Then pick up the session variable in Grid2
Problem with the first solution: Session variables are often cached in the browser, so while the first call from Grid1 sends the right primary key to Grid2, subsequent calls that try to refresh the session variable with a new primary key don't show up in the browser, because the browser grabs the value from the cache, which is the previous value
Second solution: Create a variable and attach it to the browser's window object. Then pick up the window object variable in Grid2. Since the window object is not cached, refreshing the value of the attached variable succeeds every time, and thus Grid2 receives the right ID every time
Problem with the second solution:
While it is easy enough to display window[] variables in a freeform HTML section, it is quite a different story trying to tell a server-side Xbasic function what those variables are. I've seen some pretty creative solutions having to do with storing a variable to a calculated hidden grid column etc., but they all had inherent problems for my purposes, so the search continued. And continued. And continued. Until finally I figured out how to...
How to do it anyway:
1. During the ajax callback call from a button on Grid1 row to Grid2 create a window variable in inline-javascript such as:
followed by "Open a Grid Component" Action Script
2. In grid2 you can use an action button's javascript to call an xBasic function that receives the window[] variable as follows:
The trick here, of course, is to use the "Additional data to submit" -feature of the ajax callback action javasript. And that is what allows Javascript communicate with Xbasic.
When you examine the e. object properties in the InsertData Xbasic function with the debugger, you will see that one of the variables passed as its property is "e.vendorid_", which has the value of window['wvE_EVENTID'], which in turn was set in Grid1. So now you can have your parent grid primary key and eat it too!
And who says an old dog can't learn new tricks?
Thank you. Thank you very much.
Task: Grid1 row calls Grid2, and Grid2 needs to know the primary key (row ID) of the calling row in Grid1.
First solution: Create a session variable during the call from Grid1, and store the primary key in that variable. Then pick up the session variable in Grid2
Problem with the first solution: Session variables are often cached in the browser, so while the first call from Grid1 sends the right primary key to Grid2, subsequent calls that try to refresh the session variable with a new primary key don't show up in the browser, because the browser grabs the value from the cache, which is the previous value
Second solution: Create a variable and attach it to the browser's window object. Then pick up the window object variable in Grid2. Since the window object is not cached, refreshing the value of the attached variable succeeds every time, and thus Grid2 receives the right ID every time
Problem with the second solution:
While it is easy enough to display window[] variables in a freeform HTML section, it is quite a different story trying to tell a server-side Xbasic function what those variables are. I've seen some pretty creative solutions having to do with storing a variable to a calculated hidden grid column etc., but they all had inherent problems for my purposes, so the search continued. And continued. And continued. Until finally I figured out how to...
How to do it anyway:
1. During the ajax callback call from a button on Grid1 row to Grid2 create a window variable in inline-javascript such as:
Code:
window['wvE_EVENTID'] = {grid.Object}.getValue('G','E_EVENTID', {Grid.RowNumber});
2. In grid2 you can use an action button's javascript to call an xBasic function that receives the window[] variable as follows:
Code:
var rowNum = {grid.object}._selectedRow; var additionaldata='vendorid ='+window['wvE_EVENTID']; {grid.Object}.ajaxCallback('G',rowNum,'InsertData','','_getData=true&'+additionaldata);
When you examine the e. object properties in the InsertData Xbasic function with the debugger, you will see that one of the variables passed as its property is "e.vendorid_", which has the value of window['wvE_EVENTID'], which in turn was set in Grid1. So now you can have your parent grid primary key and eat it too!
And who says an old dog can't learn new tricks?
Thank you. Thank you very much.
Comment