AnsweredAssumed Answered

How can I save complex data fields in custom field controls

Question asked by jeffrosler on Jul 11, 2018

Hi All,

 

Can anyone tell me (or point me to any docs/samples) on how to create a custom field type that stores non-primitive/complex data? I'm using APS 1.8.1 and want to store an array of values in my custom field (multi-item select for users and groups). In the stencil editor I left the Field value property and Field value type as value and string. The field value type just has string, number, date, and boolean as options. I couldn't find these in the online docs, so I'm unclear if these are the actual value or something else and how I'd set something other than those 4 field types.

 

I set the form data  through a REST call to activiti-app/api/enterprise/task-forms/<task id>/save-form and the request body had the following content. Note, that the value of approvers is a JSON array with two strings (u2 and g4).

 

requestBody={"values":{"myrichtext":"<p>Some new stuff</p>","approvers":["u2","g4"],"reviewers":[]}}

 

However when I make a REST call to get the task form info (e.g. activiti-app/api/enterprise/task-forms/<task id>), I see that the JSON for my control's value has been "stringified". Looking at the snippet of the JSON response, you see that the value field of approvers is now a string ("value": "[u1, g4]") where I set it to an array ("approvers":["u2","g4"]).

 

{ "fieldType": "FormFieldRepresentation", "id": "approvers", "name": "Approvers", "type": "user_group_picker", "value": "[u1, g4]", "required": false,

 

I suppose I can parse that invalid JSON value into an array, but it seems kind of wrong to do that. It seems like the better thing to do would be to set up the stencil value to correctly handle an array of strings, but I'm a bit unclear on how to do that. The samples I've seen in the blog posts and docs all seem pretty simple or don't address the setup.

 

Thanks for any and all help!

Outcomes