Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
eval ('x=' + http.get('http://localhost:8082/database/BIRT/getOrderNumber?cid=' + 
	customerId.value + '&did=' + department.value));

Stored Procedure to Insert Rows

Here is an example of using a Stored Procedure with an insert statement that can be called in a business rule using http.get. For this example we created a table 'interns' in the Classic Models sample database.

Code Block
use classicmodels;
CREATE TABLE interns (
  `AutoID` int(11) NOT NULL AUTO_INCREMENT,
  `StartDate` varchar(255) DEFAULT NULL,
  `JobType` varchar(255) DEFAULT NULL,
  `JobTitle` varchar(255) DEFAULT NULL,
  `NameOfIntern` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`AutoID`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=latin1;

Create the Stored Procedure.

Code Block
titleStored Procedure
DELIMITER $$
CREATE PROCEDURE `SP_Interns`(IN StartDate varchar(255),IN JobType varchar(255),IN JobTitle varchar(255),IN NameOfIntern varchar(255))
BEGIN
INSERT INTO interns (StartDate,JobType,JobTitle,NameOfIntern) VALUES (StartDate,JobType,JobTitle,NameOfIntern);
SELECT
    MAX(AutoID) AS autoid
FROM
    interns;
END$$
DELIMITER ;

Add this query to the configuration.xml file.

Code Block
titleconfiguration.xml
<queryset name='interns'>
   	<query name="interns_forschema">
	            <retrieve>
	                <statement>SELECT StartDate,JobType,JobTitle,NameOfIntern FROM interns</statement>
	            </retrieve>
	        </query>
	        <query name="addInterns" autocreate="true">
	            <retrieve>
	                <statement>call SP_Interns ({StartDate}, {JobType}, {JobTitle}, {NameOfIntern})</statement>
	            </retrieve>
        </query>
   </queryset>

Create a form from the schema query above.

Image Added

Write a business rule to call the Stored Procedure. In this case we used a trigger control, but you may want to call it when a particular workflow step is completed on form.unload or another condition.

Code Block
titleRule Code
var x;
if (SendToDatabse.clicked){
eval ('x=' + http.get('http://localhost:8082/database/interns/addInterns?StartDate=' + 
	StartDate.value + '&JobType=' + JobType.value + '&JobTitle=' + JobTitle.value + '&NameOfIntern=' + NameOfIntern.value));
}	

When the user fills in the details and clicks Send to Database, the values are inserted in the 'interns' table:

Image Added

Auto Create Rows

You can set the attribute autocreate in a query element.

...