Getting the value of an auto field inserted into a SmartBox SmartObject using the SQLDataSource

Sometimes on an ASPX page you want to use a SQLDataSource to insert data into a SmartObject with an auto ID field and then pass that ID when you start a workflow through code.  I’ve done this a number of times, but every time I need to do it I have to think for a few minutes to remember how to do it.  Next time I can just read my own blog.
Take for example this simple SmartObject.  The RequestID field is an autonumber field, meaning the database will automatically increment the value when a row is inserted:

But now I want to pass this value to a process, which is being started in code.  There are a couple of simple things you must do.  First, on you web page, look at the definition of your SQLDataSource that connects to this SmartObject.  Locate your insert parameters, and add Direction=”InputOutput” or Direction=”Output” to the ID parameter:

Next, add an event handler for the Inserted event of the SQLDataSource.  You can find the value of the autonumber like below.  Now you can pass the RequestID to a datafield when you start the process.


Posted Mon, Apr 13 2009 8:58 by DavidL