Change status based on component choose

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

This widget could not be displayed.

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

i don't have errot just it not work

"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.

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)

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.

So what can I do ?!

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.

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 ?

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

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

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

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.

I need it on create issue ..

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

139 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you