Getting a Row ID without reinventing the wheel
Published 10 AUG 2009 at 12:50:00PM by Sprezz
Updated on 19 JAN 2011 at 12:50:00PM
A new customer more accustomed to SB+ recently queried how they could access the data AFTER a read, but BEFORE the row was displayed on screen.
The first solution was just to use code called from a quick event as this would be after a read but before the user was able to undertake any actions. This was all well and good but if the screen were to be reconfigured based upon the contents of the row, there would be a slight flicker as the data displayed and then redrew. If this was unacceptable then the only other way would be to modify the Read event handler to get the row id, read the row, take the necessary actions then allow the read to proceed.
This is actually straightforward except for the process of getting the row id - which we've all had to do at some stage. Perhaps not surprisingly (given we've all had to do it at some stage ;)) a routine already exists in OpenInsight to achieve this. It is called OIWin_GetKey.
OIWin_GetKey is a function that takes two parameters - the Window name to retrieve the row id for, and a boolean flag indicating that if true only full row ids should be returned - if parts are missing then null should be returned and if false that partial row ids are acceptable.
The code to achieve the results required then becomes
0001 declare function oiWin_GetKey 0002 $insert logical 0003 0004 rowID = oiWin_GetKey( @window, TRUE$ ) 0005 if len( rowID ) then 0006 convert @fm to "*" in rowID 0007 row = xlate( "MYTABLE", rowID, "", "X" ) 0008 * Take Action…. 0009 end
[EDIT - 19 Jan 2011]: The returned key is @fm-delimited for multiple parts - the example above has been corrected to reflect this.