Sending a Record to a Workflow Rule
Sending a Record to a Workflow Rule
To send a single record, pass it as an argument to the
Workflow.callMethod()
method:
var employeeRecord = this.prgFormWizard_employeeForm.getOutboundRecord();
try {
var result = Workflow.callMethod(
'AbSolutionsViewExamples-LogicExamples-saveEmployee', employeeRecord);
You need to use the Form.getOutboundRecord() method instead of the Form.getRecord(), because the former converts the record field values into the Archibus neutral format that must be used to send the data to the server.
If you are not getting the record from a form (for example, when the record is created programmatically), you need to use the DataSource.processOutboundRecord() method to convert the field values to the Archibus neutral format:
var record = new Ab.data.Record({
'wr.status': 'Created',
'wr.requestor': View.user.name},
true); // true means new record
record = this.requestDataSource.processOutboundRecord(record);
try {
var result = Workflow.callMethod(
'AbSolutionsViewExamples-LogicExamples-saveEmployee', record);
The workflow rule declaration should define the parameter of type DataRecord:
public String saveEmployee(DataRecord employeeRecord)
{ ...
Sending Records to Old-style Workflow Rules
If the workflow rule is not defined using class-level security, then the Java Script code uses the
Workflow.call()
method:
var record = this.requestForm.getOutboundRecord();
try {
Workflow.call('AbSolutionsViewExamples-saveRequest', record);
} catch (e) {
Workflow.handleError(e);
}
The workflow rule Java code can get the record by parsing the record JSON object:
Map fieldValues = parseJSONObject(context, record);
If you need to pass additional parameters, use the parameters object for the record and all other parameters:
var record = this.requestForm.getOutboundRecord();
try {
Workflow.call('AbSolutionsViewExamples-saveRequest', {
record: record,
notifyMe: this.notifyMe
});
} catch (e) {
Workflow.handleError(e);
}
The workflow rule Java code can get the record by calling the method
context.getParameter()
:
String record = (String) context.getParameter("record");