script runner cannot create a task for specific user

Script runner 3.0.9

JIRA 6.3.11

One user with the same right than me cannot create a task during a transition...

here the log :

2015-03-18 16:13:54,032 http-bio-8090-exec-21 ERROR fbernier 973x208702x1 108dwji 192.9.244.103,192.9.244.161 /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: ST-40171, actionId: 891, file: <inline script>
java.lang.NullPointerException
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:1003)
at com.atlassian.jira.issue.Issue$getCustomFieldValue$0.call(Unknown Source)
at com.atlassian.jira.issue.Issue$getCustomFieldValue$0.call(Unknown Source)
at Script2.run(Script2.groovy:52)

 

 

Please, someone can help me azap ?

 

the script :

import com.atlassian.jira.user.UserUtils
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.util.ImportUtils
import com.atlassian.crowd.embedded.api.User
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category
import com.atlassian.jira.issue.fields.CustomField
 
log = Category.getInstance("com.onresolve.jira.groovy.CreateDependentIssue")
 
// Configurable section
def projectName = "Technician" // Name of project you want to create the issue in
def CustomTechFieldName = "customfield_11812"
//def CustomTerminalName = "customfield_11811"
def customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
CustomField customFieldTech = customFieldManager.getCustomFieldObject(CustomTechFieldName)
//CustomField customFieldTerminal = customFieldManager.getCustomFieldObject(CustomTerminalName)
def customFieldTechVal = issue.getCustomFieldValue(customFieldTech).name
//def customFieldTerminalVal = issue.getCustomFieldValue(customFieldTerminal)

// for other customisations change the code below
issueMgr = ComponentManager.getInstance().getIssueManager()
projectMgr = ComponentManager.getInstance().getProjectManager()
 
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
User currentUserObj = UserUtils.getUser(currentUser);
def wasIndexing = ImportUtils.indexIssues
ImportUtils.indexIssues = true
issueFactory = ComponentManager.getInstance().getIssueFactory()
newissue = issueFactory.getIssue()
newissue.setSummary (issue.summary) 
//+" - "+customFieldTerminalVal
newissue.setProject (projectMgr.getProjectByName(projectName))
newissue.setIssueType (issue.getIssueType())
newissue.setComponentObjects(issue.getComponentObjects())
newissue.description = issue.description
newissue.assignee = UserUtils.getUser(customFieldTechVal);
newissue.reporter = issue.getAssignee()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Location'}
newissue.setCustomFieldValue(cf, issue.getCustomFieldValue(cf))
 
params = ["issue":newissue]
subTask = issueMgr.createIssue(currentUserObj, params)
println subTask.get("key")
 
// get the current list of outwards depends on links to get the sequence number
linkMgr = ComponentManager.getInstance().getIssueLinkManager()
def sequence = 0
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
    if ("Blocks" == link.issueLinkType.name) {
        sequence++;
    }
}
 
linkMgr = ComponentManager.getInstance().getIssueLinkManager()
// TODO: Should check that 10000 is always the link id for Blocks
linkMgr.createIssueLink (newissue.id, issue.id, 10000, sequence, currentUserObj)
ImportUtils.indexIssues = wasIndexing

 

 

 

1 answer

Hi @Olivier Albertini,

It looks like when you are trying to call

def customFieldTechVal = issue.getCustomFieldValue(customFieldTech).name

you are getting a null pointer exception.

That is probably happening because customFieldTech is not present (is null) in the issue from which the other user is trying to call the transition. Therefore an exception is thrown due to the fact that you are trying to retrieve the property "name" from a null object.

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

358 views 0 6
Read article

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