We recently migrated from Jira server to cloud, which broke some of our custom post-functions. That was completely expected, but I am having trouble recreating an autoincrement post-function that we had in our server instance.
The post-function increases the value of a numeric custom field by 1. Below is the script we used in server.
Does anyone know how to translate that script into cloud-speak? I have limited technical chops and have not been able to find a solution in the forums. Thanks in advance for any ideas or guidance.
// import com.atlassian.jira.issue.CustomFieldManager
// import com.atlassian.jira.issue.fields.CustomField
// import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
// import com.atlassian.jira.component.ComponentAccessor
// import com.atlassian.jira.issue.ModifiedValue
//
// String customFieldName = "Custom field name"
// DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
// CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
// CustomField cf = customFieldManager.getCustomFieldObjectByName(customFieldName)
// Double currValue = (Double)cf.getValue(issue)
// Double newValue = currValue+1
// cf.updateValue(null, issue, new ModifiedValue(currValue,newValue), changeHolder)
Hi Becky,
I can confirm that I have an example script located here using ScriptRunner for Jira Cloud which shows how to increment a number field by a specified value each time an issue is transitioned.
This script should be run as a Run Script Post function as the Initiating User and can be used as a guide to help create the required script.
I hope this helps.
Regards,
Kristian
Hi Becky,
I am glad we were able to help solve your requirement.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Becky,
You might find https://library.adaptavist.com/entity/calculate-custom-field-on-issue-update?tab=cloud useful as an example. It calculates a field based on a couple of others, so it looks at more fields than you need, and you should actually be able to simplify it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic! From a quick pass I do understand how that script would be modified to increase a number value from 0 to 1, but I will see if I can make sense of it next week when my brain is more awake.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script gets and sets custom fields, so converting it to "read one custom field content, add one, and write it back" should not be too hard.
But yes, it's Friday, we're probably all tired, and could very much benefit from a weekend off! Give it a shot next week and if you get stuck, let us know here!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Becky
Welcome to the Atlassian community.
I personally don't have a lot of experience with ScriptRunner scripts so I don't readily have the solution available to share.
For ScriptRunner there is documentation concerning rewriting scripts:
Have you had a chance to review that material? Is there another engineer in your organization with "technical chops" that you could engage in the script rewriting efforts?
Do you have many scripts that need to be rewritten? If you do you may want to consider engaging an Atlassian Solution Partner to get help with that.
(Disclosure: I work for Praecipio, which is an Atlassian Platinum Solution Partner operating in North America. Many of my colleagues have worked on ScriptRunner script rewrites for Server to Cloud migrations.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Trudy, Thanks very much for the welcome and link to the documentation on rewriting scripts. I will review that documentation and see if I can figure out how to update the script myself. There is no engineer who can help, and we unfortunately do not have budget for a consultant.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.