Search code examples
alfrescoactiviti

Alfresco Activiti - Make Field read only for specific group/task


I'm very new to Alfresco, I have created a workflow with tasks and user groups. Now I want to know if there's a way to show the same form to a different user group with some read-only fields. There were many answers on how to do it with code, I just want to know if there's a way of doing it in the UI level (From the app)


Solution

  • You can't do this, without writing code, but I can share my suggestions, so that, some experts share their views also.

    I can see, there are 2 options.

    1. Write custom control and apply your logic (Only share side changes and may be less change in Repo side[Based on your business logic]).
    2. Create mulitple workflow forms and apply your logic in runtime and display the form dynamically.

    Option 1:

    You can refer the textfield.ftl in tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\form\controls\textfield.ftl

    While generating the textbox, Share is checking whether it has disabled option or not. If so, it adds the disabled="true" attribute.

    <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
          <input id="${fieldHtmlId}" name="${field.name}" tabindex="0"
            /* Other code lines are removed to make it simple to understand */
                 <#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if> />
          <@formLib.renderFieldHelp field=field />
    

    You can also apply similar logic to achieve for your case, but you need to write some code.

    <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
          <input id="${fieldHtmlId}" name="${field.name}" tabindex="0"
            /* Other code lines are removed to make it simple to understand */
            /* We need to determine, how we will be bringing the condition over here */
                <#if <YOUR_CONDITION> =="true")>disabled="true"</#if> />
          <@formLib.renderFieldHelp field=field />
    

    Option 2

    Share config changes.

    <!-- Edit form With All controls enabled -->
    <config evaluator="task-type" condition="example:Form1AllEnabled">
     ..
    </config>
    
    <!-- Edit form With specific controls disabled -->
    <config evaluator="task-type" condition="example:Form1FewControlsDisabled">
     ..
    </config>
    

    Workflow (bpmn file)side changes

    <userTask id="form1" name="User Update Task" activiti:assignee="${bpm_assignee.properties.userName}" activiti:formKey="${userUpdateTaskFormKey}">
    </userTask>
    

    You need to create a delegate and dynamically update userUpdateTaskFormKey variable in the execution level.

    @Override
    public void execute(final DelegateExecution delegate) throws Exception
    {
        String userUpdateTaskFormKey = "example:Form1FewControlsDisabled"; //Keeping it default
        String currentUserName  = authenticationService.getCurrentUserName();
        //Apply user business logic ....
        if (user....your condition)
        {
           userUpdateTaskFormKey =  "example:Form1AllEnabled";
        }
    
    }