Tips & tricks - Limit input to one data record

A safe and elegant solution to restrict the number of data records that can be inputted to 1 is the conditional display of buttons. With this method, a condition is specified, is performed on the server side, and depending on the result of the check, the button will be displayed or hidden. To configure the conditional display of the button, you should first activate the expert options.

Hiding the button for an existing data record

Create a button on any application page. Open the properties dialog. Activate the Conditional display setting on the "General" tab under Options.

Click on "Edit condition" and enter the following script in the Velocity Editor:

            #set($show_buttoncontrol3A451A26 = false)

## Get number of records
#set($l_statement = $PreparedQuery.prepare($DbConnection, "SELECT COUNT(*) FROM XDATAGROUP00D1A2185"))
#set($l_recordCount = $l_statement.executeAndGetScalarValue(0))
$l_statement.close()

#if($l_recordCount == 0)
	#set($show_buttoncontrol3A451A26 = true)
#end

        

The script executes an SQL statement that checks how many data records exist in the data group. If no data record is available, the button is displayed. In the script, replace the name of the button (buttoncontrol3A451A26) with the name of your button. You can determine this name in the Editor in the Application structure area. Replace the name of the data group (XDATAGROUP00D1A2185) with the name of your data group. Close the editor by clicking on "OK". Close the properties dialog for the button by clicking on "OK". Save the application. If you now open the application in the browser, the button is hidden as soon as a data record is entered in the application in the corresponding data group.

User-dependent hiding of the button for an existing data record

With this example, each user may create one data record only. Follow the same steps as in the first example but insert the following script instead of the script above:

            #set($show_buttoncontrol3A451A26 = false)

## Get number of records
#set( $l_statement = $PreparedQuery.prepare($DbConnection, "SELECT COUNT(*) FROM XDATAGROUP00D1A2185 WHERE LUSERIDINSERT = ?"))
$l_statement.setInt(1, $User.getId())
#set( $l_recordCount = $l_statement.executeAndGetScalarValue(0))
$l_statement.close()

#if($l_recordCount == 0)
	#set($show_buttoncontrol3A451A26 = true)
#end

        

Replace the name of the button and data group with the corresponding values from your application.