Getting a list of workflows relating to a user by JavaScript

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

Getting a list of workflows relating to a user by JavaScript

Jump to solution

Hi, please help.

I searched information in the Internet but no success. I have the following challenge.

How I can get a list of workflows relating to a user by simple JavaScript script  (which we plan to use as rule in future). If possible please provide a full source code.

I know how to get a list of workflows by RESTful: 

http://localhost:8080/alfresco/service/api/workflow-instances 

 but I do not know how we can call it from simple JavaScript ?!

I tried to use "remote" object in JavaScript Console (by Florian Maul) but system reported the "remote is not defined":

var url = "http://localhost:8080/alfresco/service/api/workflow-instances";
var json = remote.call(url);

I also know how to get a workflow relating to some file(s) but that's not what I'm looking for:

var docNodeRef = "workspace://SpacesStore/c86cbdb5-6bbc-4a30-8c8d-be610bee4a63";
var theDocument = search.findNode(docNodeRef);

for each(wf in theDocument.activeWorkflows)
{
logger.log(wf.);
}

So I need to get a list of all workflows relating to a some user by simple JavaScript script from user session. We plan to place this script file in "Repository -> Data Dictionary -> Scripts" and use it in Alfresco' Rule.

Thank you very much in advance for any help!

Best regards,

Egor

1 Solution

Accepted Solutions
Highlighted
Established Member

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

I don't know this is exactly which you are looking. but I have worked on workflow in javascript. So putting some snippet. 

You can try few. 

var wf = workflow.getAssignedTasks();
for (var w = 0; w < wf.length; w++) {
a = "activiti$" + wf[w].properties["bpm:taskId"];
if (a == activitiId) {
var workflowUsers = wf[w].properties["xxx:relatedUsers"].split(',');
if (workflowUsers.indexOf(user.properties.userName) > -1)
{
activiti = true;
}
}
}

others:
var task = workflow.getTask(activitiId);

View solution in original post

10 Replies
Highlighted
Established Member

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

I don't know this is exactly which you are looking. but I have worked on workflow in javascript. So putting some snippet. 

You can try few. 

var wf = workflow.getAssignedTasks();
for (var w = 0; w < wf.length; w++) {
a = "activiti$" + wf[w].properties["bpm:taskId"];
if (a == activitiId) {
var workflowUsers = wf[w].properties["xxx:relatedUsers"].split(',');
if (workflowUsers.indexOf(user.properties.userName) > -1)
{
activiti = true;
}
}
}

others:
var task = workflow.getTask(activitiId);

View solution in original post

Highlighted
Active Member II

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

Hi Ratik!

Yes this seems what I'm looking for. Let me ask two questions:

1. Where I can find a descriptions of a workflow object which used in your example ?

2. Where I can find a description of all wf[w].properties["?"] ?

Thanks a lot !

Best regards,

Egor

Highlighted
Established Member

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

Hi Egor,

You can find few APIs here and also get some idea by using core APIs.

You can check context object here.

few example:

workflowUsers.indexOf(users.properties.userName),
model.users.push(users.properties.userName),

wf[w].properties["bpm:description"];

workflow.parameters.workflowName = "";
workflow.parameters["bpm:workflowDescription"] = "";
workflow.parameters["abc:workflowRelatedUsers"] = "";
workflow.parameters["bpm:assignee"] = "";
workflow.parameters["bpm:workflowDueDate"] = "";;

Highlighted
Established Member

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution
Highlighted
Active Member II

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

Dear Ratik, 

You provide an information about how to get a list of tasks assigned on me (getAssignedTasks()Smiley Wink but could you provide also an example about - how we can get a list of tasks which a user assign to others ?

Many thanks!

Best regards,

Egor

Highlighted
Active Member II

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

Dear Ratik,

the list of Root Objects listed by the link - Surf root-scoped objectsdo not contains a reference on workflow object, why ?!

JYI 

We are using Alfresco Community 5.1

Thanks a lot !

Best regards,

Egor

Highlighted
Established Member

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution
var members = people.getMembers(people.getGroup("GROUP_Workers"));
var assignedTasks = workflow.getAssignedTasks();

var name = members.properties["cm:userName"];


You can find the desire result by using these 3 lines. Hope it will work.
Highlighted
Established Member

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution
Highlighted
Active Member II

Re: Getting a list of workflows relating to a user by JavaScript

Jump to solution

Dear Ratik,

I have checked there is no possibility to get a list of tasks assigned by a user to others by JavaScript API.

In any way Thank you very much for your answers!

Best regards,

Egor