Automatically set "Approving User" when creating work item

Description
Przemek
Posts: 10
Joined: Mon Nov 12, 2012 2:45 pm

Automatically set "Approving User" when creating work item

Postby Przemek » Thu Apr 18, 2013 7:48 am

Hello,
is there a possibility to automatically set some "Approving Users" under "Approvals" when creating a work item (i.e. change request)?
I've looked for an "init" action in the workflow designer, but "ChangeField" is only limited to date values.

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: Automatically set "Approving User" when creating work it

Postby martins » Tue Apr 23, 2013 7:03 am

You could either write your own workflow function, similar to the POP extension Set Assignee or you could use the POP extension Workitem Save in connection with a simple script that does exactly what you like.

Przemek
Posts: 10
Joined: Mon Nov 12, 2012 2:45 pm

Re: Automatically set "Approving User" when creating work it

Postby Przemek » Mon May 06, 2013 1:42 pm

Hi,

I've installed the workitem save extension. The extension itself works fine and I'm able to manipulate and run the scripts.
Unfortunately, I have trouble with the "workItem.setApprovals()" method: I get the error "[...]Cannot find function setApprovals.[...]" everytime. Can someone post a little example how to set approvals right?

martins
Posts: 181
Joined: Thu Nov 05, 2009 3:24 pm

Re: Automatically set "Approving User" when creating work it

Postby martins » Tue May 07, 2013 7:50 am

"workItem" is a object of class IWorkItem and not of class "WorkItem". Therefore you have to use the appropriate method "addAprovee".

The following example checks whether the current user is already an approvee for this workitem and if not adds him to the list of approvees.

Code: Select all

var currentuser = trackerService.getProjectsService().getCurrentUser();
var b_user_is_approvee = false;
var approval_list = workItem.getApprovals();
for (j=0; j< approval_list.size(); j++) {
   var approval = approval_list.get(j);
   if(approval.getUser().getId() == currentuser.getId()) b_user_is_approvee = true;
}
if(!b_user_is_approvee) {
   workItem.addAprovee(currentuser);
}

Przemek
Posts: 10
Joined: Mon Nov 12, 2012 2:45 pm

Re: Automatically set "Approving User" when creating work it

Postby Przemek » Tue May 07, 2013 9:29 am

Thank you very much - now all is working fine!
:D

sergeD
Posts: 21
Joined: Tue Feb 05, 2013 9:24 am

Re: Automatically set "Approving User" when creating work it

Postby sergeD » Wed Jun 26, 2013 2:05 pm

Hi

I am interested by this interesting feature, but i am not sure to fully understand how to implement it

I understand that code provided by Martins works to set as approver the current user.
Did you create a script allowing to set a list a approvers on work item , not only the current user ? Do you use this code with the save extension ?

Thanks

Sandro_F
Posts: 19
Joined: Wed Jan 19, 2011 8:40 am

Re: Automatically set "Approving User" when creating work it

Postby Sandro_F » Thu Jun 27, 2013 11:03 am

You can just use trackerService.getTrackerUser(user_id) to get a user object independing of current logged-in user. This object can be passed to workItem.addAprovee() method like in the example above.


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 3 guests