Update Status issue by post function

Z-EL April 13, 2018

Hi,

I'm trying to write a post function to change  a status issue like this : 

//to get available status because, i didn't find a way  to get a status by name

Collection<Status> status = statusManager.getStatuses();

// i do a for () to get my status id then,

Status status = statusManager.getStatus("MY_STATUS_ID");
issue.setStatus(status );

the issue is created by it is not updated.What  did i missed?

Thank you

 

 

 

1 answer

0 votes
Alexey Matveev
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.
April 13, 2018
Z-EL April 13, 2018

Thank you @Alexey Matveev for your response.

i tried this code 

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setStatusId("10104");// id of my status
TransitionValidationResult validationResult = issueService.validateTransition(issue.getCreator(), issue.getId(), 10104, issueInputParameters) ;

if(validationResult.isValid()) {
issueService.transition(issue.getCreator(), validationResult);
}else {
for(String error :validationResult.getErrorCollection().getErrorMessages()) {
        System.out.println(msg);
}

but i have an error says that we can't make a transition for an issue which his value is null.

i get my issue object  :getIssue(transientVars); 

Do you have any idea?

Thank you

Alexey Matveev
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.
April 13, 2018

Where did you put the script? If you put it in a post function, then the issue variable is already available there. You do not need to use getIssue(transientVars). You just write issue and the variable will be known by your post function.

Z-EL April 16, 2018

Hi @Alexey Matveev,

Thanks a lot for your response

yes; i'm writing a post function in java to modify the status of a issue just after creation

my Workflow is like that :

workFlow.png

for updating my transiton by

TransitionValidationResult validationResult = issueService.validateTransition(user,
issue.getId(), 11, issueInputParameters);

11 is the status ID

The issue is created but with status Open(==>i want it to be created with status Validation A if a value of costumfield is not empty)

with  this error :

It seems that you have tried to perform a workflow operation  that is not valid for the current state of this issue 

With ScriptRunner , we can do the same thing, but i need to do it with java.

What did i do wrong?

Alexey Matveev
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.
April 16, 2018

It seems that you have tried to perform a workflow operation  that is not valid for the current state of this issue 

It means that the actionId 11 does not exist for the current status of the issue

Z-EL April 16, 2018

No, i'm sure of status ID 

Status statut = statusManager.getStatus(issue.getStatusId());//open
com.opensymphony.workflow.loader.StepDescriptor currentStep = workFlow.getLinkedStep(statut);

List<ActionDescriptor> actions = currentStep.getActions();
for (ActionDescriptor action : actions) {
System.out.println(action.getName() + "===" + action.getId());
}

Any other idea ?

Thanks

Alexey Matveev
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.
April 16, 2018

Delete from your script 

issueInputParameters.setStatusId("10104");// id of my status

10104 is a status ID, but you must to pass action Id, not status Id.

Z-EL April 16, 2018

I corrected my code :

for (ActionDescriptor action : actions)
{

if ("Validation A".equals(action.getName()))
{

ApplicationUser currentUser = issue.getCreator();
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters parameters = issueService.newIssueInputParameters();
IssueService.TransitionValidationResult validationResult = issueService.validateTransition(currentUser, issue.getId(), action.getId(), parameters);
if (validationResult.isValid()) {
IssueService.IssueResult result = issueService.transition(currentUser, validationResult);
}else {

for (String msg : validationResult.getErrorCollection().getErrorMessages()) {
System.out.println("===>" + msg);
}
}
break;
}
}

But i got the same error ==>

"It seems that you have tried to perform a workflow operation (Validation A) that is not valid for the current state of this issue "

What i did wrong??

Thanks for help

Alexey Matveev
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.
April 16, 2018

Make sure that this post function is last in the list of your post functions

Z-EL April 17, 2018

It is the last one but it doesn't work.

Alexey Matveev
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.
April 17, 2018

The error means that the action can not be performed. Do you have any validators or conditions in the action?

Z-EL April 17, 2018

No, i have no validators and no conditions in the action

Z-EL April 17, 2018

There is an other way to make the same task ==> changing  a status of a issue automatically?

Thank you

Alexey Matveev
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.
April 17, 2018

You can use Fast-Track transition an issue post function to make a transition. You can find more info here:

https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_fast_track_transition_an_issue

Z-EL April 19, 2018

Hello @Alexey Matveev,

Thanks a lot for your help.

I'll try the events and see what can i make with them.

Thanks again.

Suggest an answer

Log in or Sign up to answer