Versions Compared

Key

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

...

The Database Connector supports URL parameters and JSON payload in POST/PUT requests. You can use http.post() and http.put() statements in a Live Forms business rule to send data to the frevvo Database Connector to insert/update records in into your external database.

Use the http.post method to INSERT insert records into your database and use the http.put method to update existing records.

...

  1. A Doc URI - this is the simplest way but the Doc URI is only executed when a form is submitted or a flow has completed it’s final step. When the user submits the form or completes the flow, the URI will be executed with the POST method selected from the dropdown. The database connector will execute the Insert operation identified by the URI.

    Code Block
    http://localhost:8082/database/BIRT/productDetails
  2. A  business rule to pass the data to the database connector post using URL query parameters. Business rules execute in a form/flow when the specified condition is met.   When the user clicks on the Trigger control, this rule will run and the database connector will execute the Insert operation identified by the URI in the productDetails query in the configuration.xml file..

    Code Block
    languagejs
    if (trigger.clicked) {
      var PostURL = 'http://localhost:8082/database/BIRT/productDetails?productCode=' + productCode.value + '&productName=' + productName.value + '&productLine=' + productLine.value + '&productScale=' + productScale.value + '&productVendor=' + productVendor.value + '&productDescription=' + productDescription.value + '&quantityInStock=' + quantityInStock.value + '&buyPrice=' + buyPrice.value + '&MSRP=' + MSRP.value;
      http.post(PostURL);
    } 
  3. A  business rule to create JSON to post/put in the http request. This method is preferred over method 2 because there is a limit to the length of the URL string which will limit the number of form fields you can pass to the Database Connector.

    Code Block
    languagejs
    /*member MSRP, buyPrice, productCode, productDescription, productLine, productName, productScale, productVendor, quantityInStock*/
    
    if (trigger.clicked) {
      var jp = {
        productCode: productCode.value,
        productName: productName.value,
        productLine: productLine.value,
        productScale: productScale.value,
        productVendor: productVendor.value,
        productDescription: productDescription.value,
        quantityInStock: quantityInStock.value,
        buyPrice: buyPrice.value,
        MSRP: MSRP.value,
      };
      http.post('http://localhost:8082/database/BIRT/productDetails', jp);
    } 

    Let’s analyze this rule:

    • The first line of the rule is the member directive required by the Live Forms rule validator
    • Line 2 is a conditional statement to specify that the rule runs when the Trigger control is clicked
    • var jp – defines the JSON payload variable
    • The next 9 lines define the JSON payload – specify the form field values that will be written to the columns in the products table.
    • The last line specifies the http.post operation to the database connector using the JSON payload. When the user clicks on the Trigger control, the database connector will execute the Insert operation identified by the URI in the productDetails query in the configuration.xml file..

...