Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create multiple tasks dynamically for assigned users from comala workflow

Karteek
Contributor
August 28, 2019

I have a  workflow which is have an review state, In that state i need to create tasks for all the assigned users as soon as reviewers got assigned to the workflow.

Please suggest.

3 answers

0 votes
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2019

Hey, Karteek.

ScriptRunner for Confluence can do this. There's a few pieces to put together:

You can create event listeners which listen for Comala events. See the ScriptRunner docs for an example of creating issues in a linked Jira instance based on Comala Workflow events. Comala helpfully document their workflow events, and I think the event you'll want is the ApprovalAssignedEvent. You'll need to check the event properties to make sure your page is in the review state.

import com.atlassian.sal.api.component.ComponentLocator
import com.comalatech.workflow.TaskService
import com.comalatech.workflow.event.approval.ApprovalAssignedEvent
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.comalatech.workflow")

def event = event as ApprovalAssignedEvent

// The line below limits this to one space and a workflow state named Review. You can change that to suit your needs
if (event.abstractPage.spaceKey == "MYSPACE" && event.state.name == "Review") {
def taskService = ComponentLocator.getComponent(TaskService)

//Get the list of assignees
def users = event.assignment.assigneesUserNames

users.each { username ->
taskService.createTask(
event.abstractPage,
"Review task for $username",
username,
"Do what you need to do", //Task comment
new Date() + 7 //Optionally, set a due date for one week hence
)
}
}

 

Karteek
Contributor
September 3, 2019

Hi Jhonny,

 

I have created event listener, how you suggested  however i gt an error as mentioned below. please suggest.

 

Error undefined

com/comalatech/workflow/event/approval/ApprovalAssignedEvent

Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2019

Hm. Is there any more information to the error? A screenshot might help.

Notably, when you configure the listener, you'll need to select the ApprovalAssignedEvent as shown in this screenshot:

Screen Shot 2019-09-03 at 8.04.38 AM.png

What versions of ScriptRunner & Comala Workflows were you using?

Karteek
Contributor
September 4, 2019

Please note that it is to create multiple tasks in confluence not in Jira

Karteek
Contributor
September 4, 2019

Please find the exception as below:

java.lang.NoClassDefFoundError: com/comalatech/workflow/event/approval/ApprovalAssignedEvent
at workflow.example.Script334.run(Script334.groovy:16)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:94)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$1.callCurrent(Unknown Source)
at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runStringAsScript(AbstractScriptRunner.groovy:192)
at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$6.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:76)
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate$doScript$3.call(Unknown Source)
at com.onresolve.scriptrunner.canned.confluence.events.SimpleScriptedEventHandler.doScript(SimpleScriptedEventHandler.groovy:56)
Caused by: java.lang.ClassNotFoundException: com.comalatech.workflow.event.approval.ApprovalAssignedEvent

Karteek
Contributor
September 4, 2019

adaptivist  Version: 5.5.11

Comala: v. 6.3.1

0 votes
James Conway
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2019

Hi Karteek,

It sounds like you want to assign different tasks to different users. I suggest that you consider using Parameters to define the different roles and then you can assign specific tasks to each role.

Take a look at https://wiki.comalatech.com/display/CWL/Parameter+References 

Hope that helps, our support team is always available if you have further questions.

James

0 votes
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2019

Hey, Karteek.

ScriptRunner for Confluence can help you do this.

You can create event listeners which listen for Comala events. See the ScriptRunner docs for an example of creating issues in a linked Jira instance based on Comala Workflow events. Comala helpfully document their workflow events, and I think the event you'll want is the ApprovalAssignedEvent.

Here is some example code that should create one task for every user that was assigned to approve the workflow. Obviously, you'll want to change certain values to fit your use case. I've tried to point those out in code comments, but if you have any questions, let me know!

As always, we recommend that you test your adjusted code in a test instance of Confluence to make sure it does what you want before you push this into production. :)

import com.atlassian.sal.api.component.ComponentLocator
import com.comalatech.workflow.TaskService
import com.comalatech.workflow.event.approval.ApprovalAssignedEvent
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.comalatech.workflow")

def event = event as ApprovalAssignedEvent

// The line below limits this to one space and a workflow state named Review. You can change that to suit your needs
if (event.abstractPage.spaceKey == "MYSPACE" && event.state.name == "Review") {
def taskService = ComponentLocator.getComponent(TaskService)

//Get the list of assignees
def users = event.assignment.assigneesUserNames

users.each { username ->
taskService.createTask(
event.abstractPage,
"Review task for $username",
username,
"Do what you need to do", //Task comment
new Date() + 7 //Optionally, set a due date for one week hence
)
}
}

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events