Change status based on component choose

taher shili June 9, 2017

I need to change the status issue if component = " NEW URL" i'm using the code bellow and it don't work 

import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils

 def currentComponents = issue.getComponents()
 
def workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class )
workflowTransitionUtil.setIssue(issue)
workflowTransitionUtil.setUserkey(currentUser.name)

for (c in currentComponents) {
 if (c.getName() == "NEW URL") {
  workflowTransitionUtil.setAction(191)
 }
 else {
  workflowTransitionUtil.setAction(181)
 }
}
 
workflowTransitionUtil.validate()
workflowTransitionUtil.progress()

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 9, 2017

What errors do you get in the logs?  What does "it doesn't work" mean in detail?

taher shili June 12, 2017

i don't have errot just it not work

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2017

"it does not work" is mostly useless as a problem report.

Imagine ringing a car mechanic and saying "I can't use my car".  He needs to know roughly what is wrong with it so he can bring the right tools.  "It does not work" could be a lost key, out of fuel, surrounded by a horde of angry penguins, in a ditch etc.

If your code is running and failing, there will be errors in the logs.  But your "it does not work" does not tell us where it is supposed to be running, what triggers it, or what goes into the logs.

We can't help you unless you tell us what errors you get and what "it does not work" really means.

taher shili June 12, 2017

This is the Log 


Time (on server): Mon Jun 12 2017 11:38:04 GMT+0100 (Afr. centrale Ouest) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2017-06-12 12:38:04,240 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-06-12 12:38:04,240 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script> java.lang.IllegalArgumentException: No workflow action with id '191' available for issue null at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.retrieveActionDescriptor(WorkflowTransitionUtilImpl.java:162) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.retrieveActionDescriptorWithPermissionCheck(WorkflowTransitionUtilImpl.java:146) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.getActionDescriptor(WorkflowTransitionUtilImpl.java:133) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.getFieldScreenRenderer(WorkflowTransitionUtilImpl.java:292) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.validateFieldsParams(WorkflowTransitionUtilImpl.java:255) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.access$500(WorkflowTransitionUtilImpl.java:37) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl$2.get(WorkflowTransitionUtilImpl.java:247) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl$2.get(WorkflowTransitionUtilImpl.java:236) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.impersonateUser(WorkflowTransitionUtilImpl.java:380) at com.atlassian.jira.workflow.WorkflowTransitionUtilImpl.validate(WorkflowTransitionUtilImpl.java:236) at com.atlassian.jira.workflow.WorkflowTransitionUtil$validate$2.call(Unknown Source) at Script3708.run(Script3708.groovy:23)
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2017

This error you said you didn't have is very clear: "issue: null". This means what it says.  Your script has no issue to work with.

Makes me think your script is being run in the wrong place.

taher shili June 12, 2017

So what can I do ?!

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2017

Run the script in the right place, where it has an issue context?

It's not clear what you are trying to do, or how, or where you're running this script.  You'll need to explain that if you need more help.

taher shili June 12, 2017

I need To select the next status based on the component choose Exemple : 

If Componenet == option 1

   status == " Open "

Else 

Status  == " IN PROGRESS 

do u inderstand me now ?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2017

I understand that, it's what your code tries to do, but you need to tell us where you want to do this.

taher shili June 13, 2017

thank you for ur help but that's my question is where should I put the code 

Thomas Venekamp June 13, 2017

Have you seen, that i didn't get the code to work in the create transition, but that i found a different way to achieve your goal? I answered to your question you asked here on the same topic.
Its perhaps better to ask only once to avoid duplicates in answers.

https://community.atlassian.com/t5/Questions/Change-statut-based-on-Component-on-create/qaq-p/595739

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2017

The location depends on when you want this to happen.

Do you need it as part of the workflow?  If it's for a specific transition (e.g. move from open to in-progress), then you need to do it in a post-function

If you need to run it every time a field is changed, you need to do it in a listener.

taher shili June 13, 2017

I need it on create issue ..

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2017

Ok, that's a post-function then, but because it's a change of status, it won't work.

You need to use an automatic transition, as the create issue process needs to finish before you start the next transition.

It looks like you are using "Script Runner", which does have a "fast track transition".  Rather than try to write your own (which is, at best, "painful"), you really need to use that to do it.

Suggest an answer

Log in or Sign up to answer