Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do i get the original value of the Priority field using Jira Behaviors?

Andrew L
Contributor
August 14, 2017

Hi

I have this code snippet:

def origPriority =  underlyingIssue?.priority.getName()      
log.debug(String.format("orig priority is %s", origPriority))
                                                                 

When i change the priority in the Jira UI, i expected the logfile to show me:

   orig priority is <the-original-priority>

Instead, i'm getting the changed/new priority.

So how can i get the original value of the Priority before the user changed the priority?

 I need to know if the user has changed the priority and take appropriate action if necessary.

Thanks

--Andrew

 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 11, 2023

Hi @Shah Baloch

For your requirement, you can try the sample code below:-

import com.adaptavist.hapi.jira.issues.Issues

def issue = Issues.getByKey('ST-5')

issue.update {
setCustomFieldValue('Request participants', 'ram', 'max')
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

For this code to work, please ensure that you upgrade your ScriptRunner plugin to the latest release, i.e. 8.0.0 so you can use the HAPI feature. 

I am running the sample code using the ScriptRunner console.

 

Below are a couple of test screenshots for your reference:-

1. Below is the example ticket

image1.png

2. I added the sample code to the ScriptRunner console and executed it as shown below:-

image2.png

 

3. As expected the Request participants is added as shown below:-

image3.png

I hope this helps to answer your question. :-)


Thank you and Kind regards,
Ram

Shah Baloch
Contributor
April 11, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ thank you for your reply. I don't want to update the existing tickets. I want to automate the process. Such as if a user creates a ticket and selects the component "Purchase" then it should add those two users into the Request participants field, if the component is not Purchase then it should not add those two users to the field. For the rest of the components, users can add manually if needed but just want to automate one component. Thanks

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 11, 2023

Hi @Shah Baloch

Thank you for your clarification.

If you intend to set the Requested participants field, this can only be done using the ScriptRunncer Console, Post-Function or Listener. Behaviours will not be able to do this.

Below is a working sample code using the Post-Function:-

import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.bc.project.component.ProjectComponentImpl

def issue2 = Issues.getByKey(issue.key)
def components = issue2.components as List<ProjectComponentImpl>

issue2.update {
if (components.size() > 0 ) {
components.each {
if (it.name == 'SSD') {
setCustomFieldValue('Request participants', 'ram', 'max')
} else if (it.name == 'Motherboard') {
setCustomFieldValue('Request participants', 'madona', 'amitm')
}
}
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below are the screenshots of the Post-Function configuration:-

1. Use the create transition and select the Post-Function

post1.png

2. From the Post-Function options, select ScriptRunner's Custom script post-function

post2.png

3. Add the sample code provided as shown below:-

post3.png

 

Below are a couple of test screenshots:-

1. Create a new issue and set the component to SSD

test1.png

2. Once the Issue is created as expected, the Request Participants are set to Ram Kumar and Max

test2.png

3. Create a new issue and set the Components to Motherboard.

test3.png

4. As expected, the Request Participants are set to Ajit and Madona.

test4.png

As mentioned earlier, please ensure that you upgrade your ScriptRunner plugin to the latest release, i.e. 8.0.0 to be able to use the HAPI features demonstrated above.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Like Shah Baloch likes this
Shah Baloch
Contributor
April 12, 2023

I always get confused and not know when to use Behaviour and When Listener. Thank you @Ram Kumar Aravindakshan _Adaptavist_ it worked.

TAGS
AUG Leaders

Atlassian Community Events