cancel
Showing results for 
Search instead for 
Did you mean: 

Display items of datalist in a selectOne of a workflow form

dorra87
Champ in-the-making
Champ in-the-making
Hi,
I want to create a dataList of markets and after that I want to add  in a custom workflow form a selectOne control that display markets inserted in the Market dataList.
I know how to do a custom dataList also a custom workflow but my problem is how to get the list of the markets and display them in a custom selectOne in the form of a workflow.
Did I have to do a lucene search to find the items of market datalist and if so,how I can search for the item of a custom datalist using lucene.
Thanks
1 REPLY 1

afaust
Legendary Innovator
Legendary Innovator
Hello,

you can provide dynamic data /constraints to your selectOne fields by implementing a form filter on the Repository side. form filters are called whenever a Share form for either content creation/viewing/editing or workflow/task viewing/editing is to be rendered and can enhance the auto-generated data dictionary data. Such a form filter could perform a Lucene query to collect your data list entries and set it as a LIST constraint on the propery definition.

You could implement in a manner similar to the following snippet:

@Override
public void afterGenerate(final WorkflowTask item, final List<String> fields, final List<String> forcedFields, final Form form, final Map<String, Object> context) {
   final QName taskType = item.definition.metadata.getName();
   if (this.dictionaryService.isSubClass(taskType, YourModel.TYPE_YOUR_TASK)) {
      // lookup field definition
      final String lookupDataKey = FormFieldConstants.PROP_DATA_PREFIX + YourModel.PROP_YOUR_PROP.toPrefixString(this.namespaceService).replace(':', '_');
      final List<FieldDefinition> fieldDefinitions = form.getFieldDefinitions();
      PropertyFieldDefinition propertyDefinition = null;
      boolean completed = item.state.equals(WorkflowTaskState.COMPLETED);
      for (final FieldDefinition def : fieldDefinitions) {
         if (def instanceof PropertyFieldDefinition && lookupDataKey.equals(def.getDataKeyName())) {
            propertyDefinition = (PropertyFieldDefinition) def;
            break;
         }
      }

      if (propertyDefinition != null) {
         // build constraints
         final Map<String, Object> constraintParams = new HashMap<String, Object>();
         final List<String> options = new ArrayList<String>();
         // collect your options


         constraintParams.put("caseSensitive", true);
         constraintParams.put("allowedValues", options);

         // actually constrain the field
         final FieldConstraint constraint = new FieldConstraint("LIST", constraintParams);
         List<FieldConstraint> constraints = propertyDefinition.getConstraints();
         if (constraints == null) {
            constraints = new ArrayList<PropertyFieldDefinition.FieldConstraint>();
            propertyDefinition.setConstraints(constraints);
         }
         constraints.add(constraint);
      }
   }
}

Regards
Axel