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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

135 views 1 17
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