Toggle menu

doOptionDataRead(fieldname, dbdetails)

Description

This function is called from the skeleton processor to populate the options controls of form fields (eg the radio group) with values.  The dbdetails object contains many optional fields which may be required dependent on the values of other fields. You may either:

Provide an SQL statement that selects DataValue, DataDisplay and optionally DataGroup​ from a table in the iCM database.

OR

Provide values for (at least) the table, value and display properties so that an SQL statement may be auto generated.

Parameters

NameTypeDescription
fieldnameString, requiredThe name of the field to be populated with the returned options
maxnumresultsInteger, optionalThe number of results to return
queryTimeoutInteger, optionalA number of seconds to set as the timeout for the query. If not set will default to the queryTimeout set at the worker config level (which itself defaults to 120)
dbdetailsObject, requiredThe details of the database query
dbdetails.tableString, requiredThe table that will supply the optionData
dbdetails.valueString, requiredThe column that will supply the optionData values
dbdetails.displayString, requiredThe column that will supply the optionData display text
dbdetails.groupString, optionalDefault ""

The column that will supply the optionData groups
dbdetails.orderbyString, optionalDefault ""

The column to order the optionData by
dbdetails.orderbydirString (enumeration), optionalDefault "ASC"

The direction of the ordering, "ASC" = ascending or "DESC" = descending
dbdetails.datasourceString, optionalDefault "" (the iCM database)

The datasource to be queried

Alternatively you can write an explicit SQL statement:

NameTypeDescription
fieldnameString, requiredThe name of the field to be populated with the returned options
dbdetailsObject, requiredThe details of the database query
dbdetails.sqlString (SQL), requiredAn SQL statement
dbdetails.datasourceString, optionalDefault "" (the iCM database)

The datasource to be queried

Example

​This example queries the article table of the iCM database..

function(params, credentials) {
    let request = this.callWorkerMethod( 'formutils', 'doOptionDataRead', {
        "fieldname": "FIELD1",
        "maxnumresults": 10,
        "dbdetails": {
            "table": "Article",
            "value": "ArticleID",
            "display": "ArticleHeading",
            "orderby": "ArticleID",
            "orderbydir": "ASC"
        }
    });
    return request;
}

Or, using sql:

function(params, credentials) {
    let request = this.callWorkerMethod( 'formutils', 'doOptionDataRead', {
        "fieldname": "FIELD1",
        "dbdetails":{
            "sql":"SELECT TOP 10 [ArticleID] as DataValue, [ArticleHeading] as DataDisplay FROM Article ORDER BY [ArticleID] ASC"
        }
    });
    return request;
}

Result

{
    "id": 41,
    "result": [
        ["1", "Welcome to the GOSS Docs Site", ""],
        ["2", "Hidden Articles", ""],
        ["3", "Top Utils", ""],
        ["4", "Bottom Utils", ""],
        ["1703", "The Commerce Platform", ""],
        ["1704", "iCM Management", ""],
        ["1706", "System Configuration", ""],
        ["1709", "Events", ""],
        ["1710", "Features", ""],
        ["1711", "The Forms Designer", ""]
    ],
    "jsonrpc": "2.0"
}

Last modified on August 01, 2024

Share this page

Facebook icon Twitter icon email icon

Print

print icon