Derived Attributes

Follow

Derived attributes are linked to a workflow by a workflow ID property which is specified in the principal attribute definition screen. The value of the attribute is obtained by executing the specified workflow. The result of the workflow is expected in the following JavaScript structure:

<subtype_name>: {
	<attr_name>: ["value1", ... ,"value3"],
	...
	<attr_name>: ["value1", ... ,"value3"]
}
...
<subtype_name>: {
	<attr_name>: ["value1", ... ,"value3"],
	...
	<attr_name>: ["value1", ... ,"value3"]
}

Where the values assigned to each attr_name has to be an array (even if it only contains one value)

As an example, the following workflow script produces a value for the attribute Full Name by concatenating the First Name and Last Name attribute values of the principal.

function getFullNameValues(workItem){
	var fn = workItem.input.value.attributes.common.first_name[0];
	var ln = workItem.input.value.attributes.common.last_name[0];
	var full_name = fn + " " + ln;
	var full_name_str = JSON.stringify(full_name).replace(/\"/g, "");
    workItem.output = tb.simpleResponse({
		common: {
			full_name: [full_name_str]
		}
	});
}

The workflow function is given an object as parameter, called workItem in this example, that contains the principal object (accessed via workItem.input.value) and where the output of the workflow must also be stored, in workItem.output. As shown in the example above, the output object can be created using tb.simpleResponse and passing as parameter a JavaScript object with the correct structure.

Finally, since the returned values have to be in JSON format, the full_name property is converted into a JSON String by the JSON.stringify method and the backward slashes \ created by the conversion are removed.

Have more questions? Submit a request

Comments