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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get debugging messages with variables out of scriptrunner in listener?

Hello,

I am trying to obtain a debugging message for a scriptrunner listener. It should contain variables. The code is here:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.label.Label
import com.atlassian.jira.issue.customfields.option.*
import org.apache.log4j.Level
import org.apache.log4j.Logger
import org.slf4j.LoggerFactory;

log.setLevel(Level.DEBUG)
log.debug("...")

def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def optionsManager = ComponentAccessor.getOptionsManager()

def issue = event.getIssue() as MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()

def customFieldTeam = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Team")
def customFieldTeamLabels = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Team Labels")
def labelMgr = ComponentAccessor.getComponent(LabelManager)
def existing_labels = (List <Option>) issue.getCustomFieldValue(customFieldTeamLabels)
log.debug("My variable has a value: " + existing_labels)
if(event.getChangeLog().getRelated("ChildChangeItem").find{ it.field == "Team" && it.newstring == "my_new_label"}){

for (label in existing_labels) {
log.debug("The labels are: " + label)
issue.setCustomFieldValue(customFieldTeamLabels, [label] as Set)
}

def my_new_label= new Label(null, issue.id, customFieldTeamLabels.idAsLong, "my_new_label")

issue.setCustomFieldValue(customFieldTeamLabels, [my_new_label] as Set)

}

 

The above should hopefully print all the labels inside the "existing_labels" variable, but it does not do that at all. The same goes for "label".

Thank you!

1 answer

1 accepted

0 votes
Answer accepted

HI @AramaM 

Do you get any logs output at all from your script?

When I run it in my groovy console (after small modification to manually get an issue and remove the event.getChangeLogCondition), I get this:

2020-03-03 22:22:08,089 DEBUG [runner.AbstractScriptRunner]: ... 
2020-03-03 22:22:08,092 DEBUG [runner.AbstractScriptRunner]: My variable has a value: [test2, testlabel]
2020-03-03 22:22:08,092 DEBUG [runner.AbstractScriptRunner]: The labels are: test2
2020-03-03 22:22:08,093 DEBUG [runner.AbstractScriptRunner]: The labels are: testlabel

 Where are you looking for the log output? If in scriptrunner history, I'd check directly in your atlassian-jira.log file to make sure it's not a problem with scriptrunner history.

Hi Peter, 

Thank you for your reply.

For reasons I don't know, the exact same thing now seems to be working fine for me.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

260 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you