You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Senari
1) We have custom field {text type} and custome field name is "change field info" and same custom filed id is"custome_ 23490"
Senario:
Custom field all ways needs to show the value of before updated value of "priority " filed.
Example:
Priority filed have: Low, high, medium
We changed priority field for a incident
From "Low" to "High"
Inthis case custome filed needs to show "Low" ( that means previous value of Priority Filed)
Same thing work for N number of times priority filed change.
Note: if it is no update for priority field then custome filled should be blank empty
Please let me know best approach and jira code for senario
Hi @Inetinfo Inetinfo and thanks for your question.
For which Jira environment are you asking (Cloud- Server/DataCenter)?
I think, automation or Scriptrunner would be needed for this. For example, if you are using Scriptrunner you can use a listener script in Scriptrunner to capture the "changelog" information and, based on the changes in the "priority" field, update the custom field with its previous value.
Hope this helps. If the issue is resolved, you can vote and accepted for this comment.
Best,
Murat Seven
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For which Jira environment?
For Jira Cloud;
You can use Script Listeners for this purpose. Choose the "Issue Updated" events for these listeners.
Afterward, you can make a REST API request with this script and write the result to the desired field.
def changelogResponse = get("rest/api/2/issue/${issue.key}/changelog")
.header('Content-Type', 'application/json')
.asObject(Map).body
def priorityChanges = changelogResponse.values.items.findAll{it['field'].getAt(-1) == 'priority'}
logger.info("priorityChanges: "+ priorityChanges)
def previousPriority = priorityChanges.getAt(-1).getAt(-1).fromString
// Update the issue with the PreviousPriority field
put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10071: previousPriority.toString() // customfield ID for PreviousPriority is customfield_10071
]
])
.asString()
Hope this helps.
Best,
Murat Seven
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Murat Seven Murat Seven
2023-11-16 05:55:30,147 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2023-11-16 05:55:30,148 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.get() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [rest/api/2/issue/Dcco-5675/changelog]
Possible solutions: get(java.lang.String), grep(), grep(java.lang.Object), getAt(java.lang.String), wait(), any()
at Script3018.run(Script3018.groovy:119)
......................................
code implemented on listener
// the value of the new option to set
def log = Logger.getLogger("setResolutionDate")
log.setLevel(Level.WARN)
//
// Get Managers and Components
def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def SearchService = ComponentAccessor.getComponent(SearchService)
def issueIndexService = ComponentAccessor.getComponent(IssueIndexingService.class)
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
MutableIssue issue = event.getIssue()
def commentManager = ComponentAccessor.getCommentManager()
def changelogResponse = get("rest/api/2/issue/${issue.key}/changelog")
.header('Content-Type', 'application/json')
.asObject(Map).body
def priorityChanges = changelogResponse.values.items.findAll{it['field'].getAt(-1) == 'priority'}
logger.info("priorityChanges: "+ priorityChanges)
def previousPriority = priorityChanges.getAt(-1).getAt(-1).fromString
// Update the issue with the PreviousPriority field
put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_26800: previousPriority.toString()
]
])
.asString()
........................
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.