Section | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Code Block |
---|
eval ('x=' + http.get('http://localhost:8082/database/BIRT/getOrderNumber')); onum.value = x.resultSet[0].onum; |
...
hidden | true |
---|
Generate Unique Sequential Id
This example uses a stored procedure, a table in your database, a database connector query and a business rule to generate a unique sequential number when a form loads. This number can populate a ticket or invoice number field in your form.
Step 1 - Create a table in your database (SQL Server):
Code Block |
---|
CREATE TABLE dbo.TBLUniqueID
(
UniqueID int IDENTITY(10000,1) PRIMARY KEY,
formuid varchar (255) NOT NULL
) |
Step 2 - Create a Stored Procedure (SQL Server):
Code Block |
---|
CREATE PROCEDURE dbo.getid
@formid varchar (255)
AS
SET NOCOUNT ON;
INSERT INTO [dbo].[TBLUniqueID] ([formuid]) VALUES (@formid);
SELECT * from [dbo].[TBLUniqueID] WHERE formuid = '@formid'; |
Step 3 - Add the query queries to your configuration.xml file
Code Block |
---|
<query name="insertformid" autocreate="true">
|
...
<retrieve> <statement>EXEC dbo.getid @formid = '{formuid}'</statement> </retrieve> </query> <query name="getformid"> <retrieve> <statement>SELECT [UniqueID] FROM [dbo].[TBLUniqueID] WHERE [formuid]={formuid}</statement> </retrieve> </query> |
Step 4 - Add this rule to your form
Code Block |
---|
/*member, UniqueID, resultSet*/
var x;
var formid |
...
|
...
= _data.getParameter('form.id');
if (form.load |
...
|
...
&& !ID.value) |
...
{ |
...
|
...
if (formid.length > 0) {
http.get('http://<your server>:<port>/database/ |
...
<queryset name>/insertformid?formuid=' + formid); eval ("x=" + http.get('http://<your server>:<port>/database/ |
...
<queryset name>/getformid?formuid=' + formid + '&_mediaType=json')); ID.value = x.resultSet[0].UniqueID; } } |
Add a Text control named "ID" in your form where the unique sequential number will be saved.
SQL Server
Here is an example with the syntax required for a SQL server stored procedure:
...
Add the enabled= attribute with a value of false to the <querySet/> or individual <query> elements in the configuration.xml file to completely disable it.
Code Block <dbconnector> <querySet name="BIRT" enabled="false" ...>
The same can be done by adding the enabled property with a value of false as shown below to the dbconnector.properties(standalone bundle) or frevvo-config.properties (tomcat bundle).
Code Block dbconnector.querySet@<queryset name>.enabled=false
This property disables all querysets. Add it to the dbconnector.properties(standalone bundle) or frevvo-config.properties (tomcat bundle).
Code Block dbconnector.querySet.enabled=false
...