Forums

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

Custom field values changing based on the Component/s value

Ilyas Kucukcay September 4, 2018

Hi everyone, 

I have a requirement where a custom field's values need to be changed depending on the Component/s field value. There will only be one value at a time for the Component/s field. 

I have the options to use Script Runner/Behaviours add-ons; however kinda stuck on how to proceed. 

Component A; 1,2,3

Component B; 4,5,6

Component C: 7,8,9

I'd use the cascading fields, however I do not think it allows us to use the Component/s field to base the values depending on it's values. 

Thank you very much for all the ideas in advance! 

 

2 answers

1 vote
Ravi Varma
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.
September 4, 2018

Hi @Ilyas Kucukcay,

If you can explore a custom solution then your requirement can be achieved in two steps:

  • Capture the issue updated event.
  • Check if the Component field has been updated, using the update event's change items
  • If Yes, then based on the Component field value, update the issue's custom field

Hope this helps.

Regards,

Ravi Varma

Cristian Rosas [Tecnofor]
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.
September 4, 2018

+1

"Issue updated" event includes "Create issue" event or it needs to be included aswell?

Ravi Varma
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.
September 4, 2018

You are correct @Cristian Rosas [Tecnofor].

At the first instance, Create Issue event should update the custom field value and then comes my logic for addressing Update Issue event

0 votes
Ilyas Kucukcay September 4, 2018

@Ravi Varma Thanks for the reply! That's been my thinking as well; however I am struggling on what mediums to use. Do you happen to know a direct reference that would include a sample code/script to achieve this? Just curious as someone else might have done it already. 

 

Cheers, 

Ilyas

Ravi Varma
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.
September 4, 2018

Hi @Ilyas Kucukcay,

I will be sharing the psuedo code shortly. Please bear with me.

Ping me if I am not doing in the next 2 days.

Regards,

Ravi Varma

Ilyas Kucukcay September 6, 2018

Hello @Ravi Varma Thanks again for the help, I deeply appreciate it! Any clue on how to achieve this? 

Ravi Varma
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.
September 6, 2018

Hi @Ilyas Kucukcay,

Please find the details as below. Hope it helps.

In pom.xml

dependency entry:

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>

Import Package

<Import-Package>
org.springframework.beans.*
</Import-Package>

 

In atlassian-plugin.xml

<component key="SbmEventsListener" class="com.listener.JiraListener">
<description>Creates/updates xxx based on specific JIRA issue events</description>
</component>
<component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher"/>

 

In JiraListener.java

private final EventPublisher eventPublisher

 

 

public JiraListener(EventPublisher eventPublisher) {
super();
this.eventPublisher = eventPublisher;
}

/**
* Called when the plugin has been enabled.
* @throws Exception
*/
@Override
public void afterPropertiesSet() throws Exception {
// register ourselves with the EventPublisher
eventPublisher.register(this);
log.info(IntegrationUtils.LOG_PREFIX+"Register JiraListenerForSbm to eventPublisher");
}

/**
* Called when the plugin is being disabled or removed.
* @throws Exception
*/
@Override
public void destroy() throws Exception {
// unregister ourselves with the EventPublisher
eventPublisher.unregister(this);
log.info(IntegrationUtils.LOG_PREFIX+"Unregistering JiraListenerForSbm from eventPublisher");
}

/**
* Receives any {@code IssueEvent}s sent by JIRA.
* @param issueEvent the IssueEvent passed to us
*/
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {

   //Put your logic

  //Adding my code 

Issue issue = issueEvent.getIssue();
Long eventTypeId = issueEvent.getEventTypeId();
if (eventTypeId.equals(EventType.ISSUE_CREATED_ID)) {
//set the issue's custom field value based on Component field value when issue is created
} else if (eventTypeId.equals(EventType.ISSUE_UPDATED_ID)) {
//Get the change log for component
try {
Iterator iter = issueEvent.getChangeLog().getRelated("ChildChangeItem").iterator();
while (iter.hasNext()) {
GenericValue changeItem = (GenericValue) iter.next();
String issueProperty = (String) changeItem.get("field");
String issuePropertyOldValue = (String) changeItem.get("oldstring");
String issuePropertyNewValue = (String) changeItem.get("newstring");
System.out.println(IntegrationUtils.LOG_PREFIX+"\t'"+issueProperty + "' changed from '"+issuePropertyOldValue+"' to '"+issuePropertyNewValue + "'");
//If changed issue property is Component/s then update the issue's custom field value
}
} catch (GenericEntityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events