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
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
2. I added the sample code to the ScriptRunner console and executed it as shown below:-
3. As expected the Request participants is added as shown below:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
2. From the Post-Function options, select ScriptRunner's Custom script post-function
3. Add the sample code provided as shown below:-
Below are a couple of test screenshots:-
1. Create a new issue and set the component to SSD
2. Once the Issue is created as expected, the Request Participants are set to Ram Kumar and Max
3. Create a new issue and set the Components to Motherboard.
4. As expected, the Request Participants are set to Ajit and Madona.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I always get confused and not know when to use Behaviour and When Listener. Thank you @Ram Kumar Aravindakshan _Adaptavist_ it worked.
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.