The following script does not work. I want to know why.

The following JIRA script does not work. I want to know why.

* single select field -> assign auto select

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.option.Option
import org.apache.log4j.Level

log.setLevel(Level.DEBUG)

log.debug "Starting postfunction..."
if (issue.isSubTask()) {
log.debug "Issue is subtask, leaving."
return
}


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def approver = customFieldManager.getCustomFieldObject("customfield_xxxxx")
def approverval = (issue?.getCustomFieldValue(approver) as Option)?.value

def userToReassign = issue.getAssignee()
log.debug "Got assignee ${userToReassign}."
UserUtil userUtil = ComponentAccessor.getUserUtil()

switch (approverval) {
case "A":
log.debug "Getting user for A."
userToReassign = userUtil.getUserObject("usera")
break
case "B":
userToReassign = userUtil.getUserObject("userb")
break
case "C":
userToReassign = userUtil.getUserObject("userc")
break
}

log.debug "Setting user to ${userToReassign}."
issue.setAssignee(userToReassign)

* component -> watcher user add

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()

List<String> compList= (List<String>)issue.getComponentObjects();

List<String> CompoUser = new ArrayList<String>();
CompoUser.add("usera")


for(String comp : compList) {
if(comp.indexOf("comval")>-1){ //"comval" 1ea over Component Value
for(String user : CompoUser) {
if (user) {
watcherManager.startWatching(userManager.getUserObject(user), issue.genericValue)
}
}
}
}

* single select filed -> watcher user add

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()

def single = customFieldManager.getCustomFieldObject("customfield_xxxxx") 
def options = (issue?.getCustomFieldValue(single) as Option)?.value

List<String> userww = new ArrayList<String>();
userww.add("usera");


if(options.equals("comval")){
for(String user : userww) {
if (user) {
watcherManager.startWatching(userManager.getUserObject(user), issue.genericValue)
}
}
}

* text field update

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def CepotNm = customFieldManager.getCustomFieldObject("customfield_xxxxx")//text field
def CepotFn = customFieldManager.getCustomFieldObject("customfield_xxxxx")//text field
def CepotNmVal = issue.getCustomFieldValue(CepotNm) //text field get value

if (FunNmVal.equals("A")){
String currentFieldValue = issue.getCustomFieldValue(CepotFn);
CepotFn.updateValue(null, issue, new ModifiedValue("", CepotNmVal.toString()), new DefaultIssueChangeHolder());
}
else if (FunNmVal.equals("B")){
String currentFieldValue = issue.getCustomFieldValue(CepotFn);
DepotFn.updateValue(null, issue, new ModifiedValue("", CepotCaVal.toString() +"_"+ CepotNmVal.toString() +"_"+ "HW"), new DefaultIssueChangeHolder());
}

* multi select filed -> watcher user add

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()

def multi = customFieldManager.getCustomFieldObject("customfield_xxxxx")
def options = issue.getCustomFieldValue(multi) as List<Option> //multi value

List<String> userww = new ArrayList<String>();
userww.add("usera");

if(options*.value.contains("comval")){
for(String user : userww) {
if (user) {
watcherManager.startWatching(userManager.getUserObject(user), issue.genericValue)
}
}
}

 

help.

1 answer

This widget could not be displayed.

Your going to need to spend time debugging this step by step in your IDE yourself. It's very unlikly someone is going to spend the time doing your job for you on something this big. 

You haven't even given the reason as to why this has failed in the first place

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

52 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you