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
You need to transition the issue. Kindly have a look at the code here:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Make sure that this post function is last in the list of your post functions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error means that the action can not be performed. Do you have any validators or conditions in the action?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Alexey Matveev,
Thanks a lot for your help.
I'll try the events and see what can i make with them.
Thanks again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.