cancel
Showing results for 
Search instead for 
Did you mean: 

How to get list of task initiated by the user

rockycres
Champ in-the-making
Champ in-the-making
Hi all,

I have checkout the Workflow task Api's to get the assigned task,pooled task for the user..Is there any API available to get the task which is initiated or contributed by the user to the workflow.?.Any help appreciated..
5 REPLIES 5

jayjayecl
Confirmed Champ
Confirmed Champ
Hi, for what use (dialog/wizard, webscript, dashlet etc…) ?
I got something if you want to use it in a dashlet (like if you want to customize the "My tasks" dashlet)

rockycres
Champ in-the-making
Champ in-the-making
Hi ,

I would  like to customize the My task dashlet to display also the task that has been initiated or contributed by the user.I won't worry whether it is a dashlet or webscript if it's serve my purpose.

Thanks..

sethatrothbury
Champ in-the-making
Champ in-the-making
I hate to point out the obvious, but the "My Completed Tasks" does show everything a user has had a hand in.

jayjayecl
Confirmed Champ
Confirmed Champ
I would like to customize the My task dashlet to display also the task that has been initiated or contributed by the user

All right,

1/ You have to customize the "workflow" object that is used in the "My tasks" dashlet

public class WorkflowCustom extends Workflow {

    private ServiceRegistry services;

    /**
     * Sets the service registry
     *
     * @param services
     *            the service registry
     */
    @Override
    public void setServiceRegistry(ServiceRegistry services) {
        this.services = services;
        super.setServiceRegistry(this.services);
    }

    private WorkflowService getWorkflowService() {
        return this.services.getWorkflowService();
    }

    /**
     * Convert a list of WorkflowTask items into bean objects accessable from
     * templates
     *
     * @param tasks
     *            List of WorkflowTask objects to convert
     *
     * @return List of WorkflowTaskItem bean wrapper objects
     */
    private List<WorkflowTaskItem> convertTasks(List<WorkflowTask> tasks) {
        List<WorkflowTaskItem> items = new ArrayList<WorkflowTaskItem>(tasks
                .size());
        for (WorkflowTask task : tasks) {
            items.add(new WorkflowTaskItem(this.services,
                    getTemplateImageResolver(), task));
        }

        return items;
    }

    /**
     * Return a list of objects representing the tasks initialized by the
     * current user
     *
     * @return list of WorkflowTaskItem bean objects {@link WorkflowTaskItem}
     */
    public List<WorkflowTaskItem> getInitializedTasks() {
        // get the initialized tasks by the current user
        List<WorkflowTask> tasks = null;

        // get the current username
        FacesContext context = FacesContext.getCurrentInstance();
        User user = Application.getCurrentUser(context);
        String userName = user.getUserName();

        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(context, true);
            tx.begin();

            // query for all active tasks
            WorkflowTaskQuery query = new WorkflowTaskQuery();
            tasks = this.getWorkflowService().queryTasks(query);

            // commit the changes
            tx.commit();
        } catch (Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception ex) {
            }
            Utils.addErrorMessage(
                    "Failed to get tasks initialized by the user: "
                            + e.toString(), e);
        }

        List<WorkflowTaskItem> allTaskItems = convertTasks(tasks);
        List<WorkflowTaskItem> initializedTaskItems = new ArrayList<WorkflowTaskItem>(
                allTaskItems.size());

        for (WorkflowTaskItem taskItem : allTaskItems) {
            if (taskItem.getInitiator().getNodeRef().equals(user.getPerson())) {
                initializedTaskItems.add(taskItem);
            }
        }

        Collections.reverse(initializedTaskItems);

        return initializedTaskItems;
    }

    /**
     * Return a list of objects representing the assigned tasks for the current
     * user
     *
     * @return list of WorkflowTaskItem bean objects {@link WorkflowTaskItem}
     */
    @Override
    public List<WorkflowTaskItem> getAssignedTasks() {
        // get the "in progress" tasks for the current user
        List<WorkflowTaskItem> assignedTasks = super.getAssignedTasks();
        Collections.reverse(assignedTasks);

        return assignedTasks;
    }

    /**
     * Return a list of objects representing the pooled tasks for the current
     * user
     *
     * @return list of WorkflowTaskItem bean objects {@link WorkflowTaskItem}
     */
    @Override
    public List<WorkflowTaskItem> getPooledTasks() {
        // get the "pooled" tasks for the current user
        List<WorkflowTaskItem> pooledTasks = super.getPooledTasks();
        Collections.reverse(pooledTasks);

        return pooledTasks;
    }

    /**
     * Returns owner first name
     *
     * @param owner
     * @return
     */
    public String getTaskOwnerFirstName(String owner) {
        return UserUtilsGP.getUserFirstName(owner);
    }

    /**
     * Returns owners last name
     *
     * @param owner
     * @return
     */
    public String getTaskOwnerLastName(String owner) {
        return UserUtilsGP.getUserLastName(owner);
    }

    /**
     * Returns pooled task group display name
     *
     * @param taskId
     * @return
     */
    public String getTaskPooledActorsGroup(String taskId) {
        NodeRef group = WorkflowUtilsGP.getPooledActorsGroup(taskId);
        String displayName = "";
        if (group != null) {
            displayName = UserUtilsGP.getGroupDisplayName(group);
        }

        return displayName;
    }
}

You also have to declare it in order to be taken into account :
<bean id="workflowTemplateExtension" parent="baseTemplateImplementation" class="org.alfresco.web.repo.template.WorkflowCustom">
        <property name="extensionName">
            <value>workflow</value>
        </property>
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>

in custom-template-services-context.xml


2/ Customize the dashlet :

- add a new filter in the mytasks.get.html.ftl

<li <#if filter=6>class="taskCurrent"</#if>><a href="#" onclick="MyTasks.filter(6); return false;"><span id="todoInitializedHeader" >My initialized tasks</span></a></li>
                                

- customize mytaskspanel.get.html.ftl, following the examples already in this very file

rockycres
Champ in-the-making
Champ in-the-making
Hi Jay,

It worked perfectly.Thanks very much for ur help. Smiley Very Happy

If possible,can u help me on this issue..?
http://forums.alfresco.com/en/viewtopic.php?f=30&t=19028