Syntax and Examples
This section provides you with information on the commands you can use for Stanza and the functions you can to code in Lua.
Lua v5.1 is supported in the current release.
Commands and Functions
Verify record exists (true/false) | |
---|---|
LUA Syntax | exists = gospel.existsRecord("<record-definition-id>", "<value>") |
STANZA Syntax | if exists records.<record-id>.{record.fields."<field-name>"} |
Load a record definition | |
LUA Syntax | gospel.loadRecordDefinition("<record-definition-id>") The following functions are available for record definitions: "getId" "getName" "getType" "getFields" "setName" "setVersion" "getVersion" The following functions are available for fields in record definitions: "getName" "getType" "getAllowedValues" "isMandatory" "getCurrentUserThresholdScore" "getBaseThresholdScore" "getEncryptionType" "getFieldLink" "getIndex" |
Load records with string | |
LUA Syntax | gospel.loadRecordsWithString("<record-id>", "<field-value>") |
Load records with matchers | |
LUA Syntax | //define matcher <matcher1-name> = gospel.matcher.new("record.fields.<field-name>", "EQ", "<field-value>") <matcher2-name> = gospel.matcher.new("record.fields.<field-name>", "contains", "<field-value>") //call function to match all <record-list1> = gospel.loadRecordsWithMatchers("<record-id>", "withAll", {<matcher1-name>, <matcher2-name>}) // call function to match any <record-list2> = gospel.loadRecordsWithMatchers("<record-id>", "withAny", {<matcher1-name>, <matcher2-name>}) The following functions are available for matchers: "setFieldToMatch" "getFieldToMatch" "setPredicate" "getPredicate" "setValue" "getValue" |
STANZA Syntax | set records.<record-id>.findOneWith(match.fields.<matcher-field-name1> eq "<matcher-value1>").fields.<matcher-field-name2> = "<matcher-value2>" |
Reject transaction | |
LUA Syntax | gospel.rejectTransaction("<describe-reason>") |
STANZA Syntax | reject action "<describe-reason>" |
Get current record | |
LUA Syntax | gospel.getCurrentRecord() |
Create record | |
LUA Syntax | --option 1 <fields> = {<field1-name> = "<value>", <field2-name> = "value"} <record> = gospel.record.new(<record-definition-id>, <record-id>, <fields>) --option 2 <record> = gospel.record.new(<record-definition-id>, record-id>) <fields> = {<field1-name> = "<value>", <field2-name> = "<value>"} record:setFields(fields) The following functions are available for records: "setId" "getId" "setType" "getType" "getTimestamp" "setFields" "getFields" |
STANZA Syntax | create records.<record-id>.{record.fields.<field-name>} as (field1 = {record.fields.<field-name>}, field2 = {record.fields.<field-name>}) set records.<record-id>.{record.fields.<field-name>}.fields.<field-name> = record.fields.<field-value> |
Commit record | |
LUA Syntax | gospel.commitRecord(<record-id>, "WRITE") |
STANZA Syntax | commit to records.<record-id>.{record.fields.<field-name>} as "WRITE" |
Examples
Here are examples for using Stanza/Lua stored procedures with Gospel:
LUA examples
LUA Example
local gospel = require("gospellua") --verify record A001 exists in record definition Employees if gospel.existsRecord("Employees", "A001") exists then --get current record gospel.getCurrentRecord():getFields()["Department"] = "Finance" --commit record gospel.commitRecord(gospel.getCurrentRecord(), "WRITE") end
LUA Example
--Load a record emp001 in record definition Employees with strings local gospel = require("gospellua") records = gospel.loadRecordsWithString("Employees", "emp001") if gospel.getCurrentRecord():getFields()["invoiceId"] == "invoice001" then name = records[1]:getId()..records[2]:getId() f = {consent = "true", time = "1483756270472", sequenceNumber = table.getn(records), name = name} record = gospel.record.new("DefinitionFieldTypes", gospel.getCurrentRecord():getFields()["invoiceId"], f) gospel.commitRecord(record, "WRITE") end
LUA Example
--Load a record with matchers local gospel = require("gospellua") matcher1 = gospel.matcher.new("record.fields.name", "EQ", "user2") matcher2 = gospel.matcher.new("record.fields.decimalValue", "contains", "3500") records = gospel.loadRecordsWithMatchers("Employees", "withAll", {matcher1, matcher2}) if gospel.getCurrentRecord():getFields()["invoiceId"] == "invoice001" then f = {consent = "true", time = "1483756270472", sequenceNumber = table.getn(records), name = records[1]:getId()} record = gospel.record.new("DefinitionFieldTypes", gospel.getCurrentRecord():getFields()["invoiceId"], f) --commit record gospel.commitRecord(record, "WRITE") end
LUA Example
--reject a transaction local gospel = require("gospellua") if gospel.getCurrentRecord():getFields()["invoiceId"] == "invoice001" then gospel.rejectTransaction("Reject this transaction") end
Stanza example
Stanza example
// Check mandatory fields EmployeeID and PersonID in Employees are not empty if record.fields.EmployeeID EQ "" OR record.fields.PersonID EQ "" then reject action "Fields EmployeeID and PersonID cannot be empty" end if // Check if the person exists yet if not exists records.EmpPerson.{record.fields.PersonID} then // make a new person create records.EmpPerson.{record.fields.PersonID} as (GivenName = record.fields.GivenName, FamilyName = record.fields.FamilyName, PersonID = record.fields.PersonID) else // Person exists. Copy the locical person specific datails over // Copy all fields that are not empty if record.fields.GivenName NE "" then set records.EmpPerson.{record.fields.PersonID}.fields.GivenName = record.fields.GivenName end if if record.fields.FamilyName NE "" then set records.EmpPerson.{record.fields.PersonID}.fields.FamilyName = record.fields.FamilyName end if end if // Check if the employee exists yet if not exists records.EmpEmployee.{record.fields.EmployeeID} then // make a new employee create records.EmpEmployee.{record.fields.EmployeeID} as (EmployeeID = record.fields.EmployeeID, PersonID = record.fields.PersonID) end if // Update the records commit to records.EmpEmployee.{record.fields.EmployeeID} as "WRITE" commit to records.EmpPerson.{record.fields.PersonID} as "WRITE"