Forums

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

Listener not working if project name is not specified

Vineela Durbha
Contributor
November 28, 2019

Hi 
I have written a listener to change the Assignee to component lead when ever component is being changed. I can see in the log and backend script is executing and component owner/assignee is being changed. But on UI unless the project name is mentioned , assignee field value is not being changed. 

Is it mandatory to mention the project name for listeners

2 answers

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
November 29, 2019

Hi @Vineela Durbha ,

You should set the project in the listener configuration. Do you mean you needed to mention the project name in the script ?

Vineela Durbha
Contributor
November 29, 2019

Hi @Antoine Berry 

I am talking about mentioning the project in listener configuration. Actually I have the script which should work for the entire project category.So I am looking for what happens if project name is not added under the listener configuration, as my script should work for the entire project category.

Antoine Berry
Community Champion
December 3, 2019

Sorry I completely missed your answer... As Ilya said you could create a listener for all projects and filter the project category in the script itself.

Vineela Durbha
Contributor
December 3, 2019

@Antoine Berry 

I tried the above but it is not working unless and until you provide the project name in script listener UI page

Antoine Berry
Community Champion
December 4, 2019

@Vineela Durbha could you please provide a screenshot of you configuration / script ? It would be easier to debug it.

Vineela Durbha
Contributor
December 4, 2019

@Antoine Berry 

Please find the attached screenshot . I have tried not to mention any project under projects and because of this assignee value is not getting changed inspite of mentioning that in the script. My script is as below

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent;
import org.apache.log4j.Level
import org.apache.log4j.Logger

Helper helper = new Helper();

log.setLevel(org.apache.log4j.Level.DEBUG)
def issue = event.issue as Issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();

def changeHolder = new DefaultIssueChangeHolder();

 

log.debug("project category" +issue.getProjectObject().getProjectCategoryObject().getName())

def components = issue.componentObjects.toList()

if(issue.getProjectObject().getProjectCategoryObject().getName()=="Software - Lightweight"){
if(helper.CheckIfSpecificCustomFieldChangedValue(event,"Component"))
{
log.debug("yes component value is changed")
issue.setAssignee(components?.first()?.componentLead)
log.debug("assignee " +issue.getAssignee().getDisplayName())
}
}

 

This works only if I mention specific project under projects in Listener UI. But when i try to display the assignee value in the script, I can see the new assignee but the value is not being reflected on UI. So I guess value is getting changed but not being reflected in UICapture.PNG

Antoine Berry
Community Champion
December 4, 2019

With that current configuration the listener will indeed not execute, kindly try to map it with all projets : 

image.png

Vineela Durbha
Contributor
December 4, 2019

@Antoine Berry 

With All projects it is not working. I can see that script got executed successfully, but on UI assignee value is not changed.Capture.PNG

Antoine Berry
Community Champion
December 4, 2019

If I am not mistaken the script should display the assignee if it is updated ?

Antoine Berry
Community Champion
December 4, 2019

Also you could try to add 

import com.atlassian.jira.issue.index.IssueIndexingService

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issue.store()
issueIndexingService.reIndex(issue)

after updating the assignee in the script.

Like Vineela Durbha likes this
Vineela Durbha
Contributor
December 5, 2019

@Antoine Berry 

By adding above code script is working for "All projects" under Listener. 
Thanks for helping me resolve this issue.

Like Antoine Berry likes this
0 votes
Ilya Turov
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.
December 3, 2019

I guess, since components are bound to a projects, you have to select the context for your listener, "All projects" might work for you (unfortunately, there's no option to select project category).

Vineela Durbha
Contributor
December 3, 2019

All projects is not working unless specific projects are mentioned under Listener in UI ,inspite of mentioning the project category under scripts

Suggest an answer

Log in or Sign up to answer