Kbase 17611: Programatically assigning key fields (getInsertValue)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
Programatically assigning key fields (getInsertValue)
Using Apptivity to set the primary field of a table.
This example is based on the Tutorial in 2.0 with two additional
steps. The first is to add another data source. The second is
to add a server event. This example generates a new SupplierID
value and assigns it when the user adds a new supplier record.
You should note that this example is just a simple illustration.
It does not handle record lock issues or record deletions.
getInsertValue is called for each column in a table that did not get a
value sent into the addNew process, i.e. fields that the client did
supply a value for.
First, from the completed tutorial add a new data source called
ds_master2 that uses the master connection. The query for this
is:
SELECT Max(Suppliers.SupplierID)
FROM Suppliers
GROUP BY Suppliers.SupplierID
Next, on the ds_master data source add a server event of
getInsertValue. Then modify it to look like this:
public class tutorialds_masterQueryEvents extends abQueryEvents
{
public String getInsertValue (abQueryImpl arg, String name)
throws Exception
{
int newvalue = 0;
if (name.equals("SupplierID"))
{
abServer abs = arg.getServer();
try
{
abs.reQuery("ds_master2");
abDataRows dr = abs.getRows("ds_master2", 1, 1000,
false, 0L);
newvalue = ((Integer) dr.getColValue(0)).intValue();
newvalue += 1;
} catch (Exception e)
{ e.printStackTrace();}
return (String.valueOf(newvalue));
}
else
return (null);
}
}
Progress Software Technical Support Note # 17611