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

AramaM March 2, 2020

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
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 3, 2020

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.

AramaM March 4, 2020

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
AUG Leaders

Atlassian Community Events