I have added a custom field for target version and when i create the issue, I can see the target version as the correct release version but the Fix Version built in one is set as None. What should I write in my script to make that the same as the value in my custom field? I have the version object as well as the version name string, but what exactly should be the line of code to set the fix version as that object ?
Dear @Shagufta Gurmukhdas, if you hava version object then to set this only version you can use this
issue.setFixVersions(Arrays.asList(version))
Note, that all other version will be deleted.
Worked, thanks a lot! @Vasiliy Zverev btw i am able to write this on the create postfunction, for the subtasks created for the issue currently being created. But for this parent issue, writing this same code doesnt work. Nor does anything else, like setting the summary etc. (in the create postfunction of issue being created) How to set the fields of the current issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On create transition it is requred:
Add code to store changes
ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build() )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here issue is the original issue? or the one with updated fields?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the same as here: https://answers.atlassian.com/questions/44353347
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I did that, but somehow this current issue still doesnt get updated..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you provide full code for this post-fucntion?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is related to my other question..I want to update the current issue's version
import com.atlassian.jira.project.version.Version import com.atlassian.jira.project.version.VersionManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.project.Project VersionManager versionManager = ComponentAccessor.versionManager def customFieldManager = ComponentAccessor.getCustomFieldManager() CustomField versionCF = customFieldManager.getCustomFieldObjectByName("Version/Release") String valueOfversionType = issue.getCustomFieldValue(versionCF) String versionstring=valueOfversionType.substring(1,valueOfversionType.size()-1) Version versionn = versionManager.getVersion(issue.getProjectId(), versionstring) issue.setFixVersions(Arrays.asList(versionn)) def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() ComponentAccessor.getIssueManager().updateIssue(user, issue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false)
@Vasiliy Zverev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Whether I do this for the version or any other field like summary, description etc, it doesn't update the current issue's field. (The one for which the post function is being written)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Vasiliy Zverev Even a simple statement like this doesnt work for the current issue
issue.description = "abc"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I could simply put it in a post function for updating field( the default inbuilt postfunction) but i need to make this conditional, i.e dependent on some other field, hence I want to do it manually, but this isnt working (I am on the cloud instance)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh! I got the answer! The postfunction is supposed to be put before that of the issue actually being created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
All of the coded posted above will not work on Cloud as the API is totally different. The order of post functions in the cloud is not guaranteed as they are processed asynchronously.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shagufta,
The following code will set the fix version in ScriptRunner for JIRA Cloud for the issue with key SAMPLE-1
def issueKey = 'SAMPLE-1' def result = put('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .body([ fields:[ fixVersions: [[name: 'Version 1.0.1']] ] ]) .asString() if (result.status == 204) { println 'Successfully set version to 1.0.1' } else { println "Failed to set version to 1.0.1 ${result.status}: ${result.body}" }
Regards, Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the Script Runner for JIRA Cloud documentation is an example groovy script to calculate value of one custom field based on another as a Script listener. You can create new script listener to listen to Issue created event and based on the example set custom field value. Or if you want to copy custom field value once you can use Built-in script. Please have a look if that helps.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.