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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.