Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Custom field all ways needs to show the last priority field updated info

Edited

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 

 

 

1 answer

0 votes
Murat Seven
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.
Nov 14, 2023

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

 

 

 

 

Thanks @Murat Seven 

Yes it's script runner

Can you expand the steps and code

Murat Seven
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.
Nov 14, 2023

Hi @Inetinfo Inetinfo 

 

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

Thank you @Murat Seven Murat Seven

getting following error 

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()

 

........................

Suggest an answer

Log in or Sign up to answer