set customer request type with script runner

My version of script runner is  3.0.9

 

When I create a task by an agent, I want to create another and link the tasks in JSD 2.2 project.

I need to change the value of customer request type.

When I use automation, I m able to edit the issue and change the customer request type. But I would like to use script runner ...

If I remove the edition of customfield for customer request type, the task is created. 

 

So something is wrong with :

[...]
def cfrt = customFieldManager.getCustomFieldObjects(newissue).find {it.name == 'Customer Request Type'}
[...]
newissue.setCustomFieldValue(cfrt, 'im/scanner-management-system')

 

Here my code

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 = "Dicom Management" // Name of project you want to create the issue in
//def CustomRequestTypeName = "customfield_10010"
//def CustomTerminalName = "customfield_11811"
def customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
//CustomField customFieldRequestType = customFieldManager.getCustomFieldObject(CustomRequestTypeName)
//CustomField customFieldTerminal = customFieldManager.getCustomFieldObject(CustomTerminalName)
//def customFieldLocationVal = issue.getCustomFieldValue(customFieldLocation)
//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()
def cfrt = customFieldManager.getCustomFieldObjects(newissue).find {it.name == 'Customer Request Type'}
//newissue.setSummary (" PAIE - "+issue.summary+"- "+customFieldTerminalVal)
newissue.setSummary (" PAIE - "+issue.summary)
newissue.setProject (projectMgr.getProjectByName(projectName))
newissue.setIssueType (issue.getIssueType())
newissue.description = issue.description
newissue.assignee = UserUtils.getUser("oalbertini");
newissue.reporter = UserUtils.getUser("oalbertini");
newissue.setCustomFieldValue(cfrt, 'im/scanner-management-system')
//newissue.setCustomFieldValue(customFieldRequestType, "im/scanner-management-system")
 
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 Gantt: finish-start
linkMgr.createIssueLink (newissue.id, issue.id, 10000, sequence, currentUserObj)
ImportUtils.indexIssues = wasIndexing

 

I have the following error :

*************************************************************************************
2015-02-23 14:20:55,763 http-bio-8090-exec-13 ERROR oalbertini 860x478289x1 1h891ap  /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: IM-230, actionId: 851, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.managers.DefaultCustomFieldManager.getCustomFieldObjects(DefaultCustomFieldManager.java:272)
	at com.atlassian.jira.issue.CustomFieldManager$getCustomFieldObjects.call(Unknown Source)
	at Script11.run(Script11.groovy:37)
2015-02-23 14:20:55,781 http-bio-8090-exec-13 ERROR oalbertini 860x478289x1 1h891ap  /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2015-02-23 14:20:55,781 http-bio-8090-exec-13 ERROR oalbertini 860x478289x1 1h891ap /secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: IM-230, actionId: 851, file: <inline script>
com.atlassian.jira.exception.CreateException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@47485a23: root cause: java.lang.NullPointerException
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:695)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:618)
	at com.atlassian.jira.issue.IssueManager$createIssue.call(Unknown Source)
	at com.atlassian.jira.issue.IssueManager$createIssue.call(Unknown Source)
	at Script9.run(Script9.groovy:50)
Caused by: com.atlassian.jira.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@47485a23: root cause: java.lang.NullPointerException
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:909)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:684)
	... 4 more
Caused by: com.opensymphony.workflow.WorkflowException: An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@47485a23: root cause: java.lang.NullPointerException
	at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1523)
	at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:879)
	... 5 more
Caused by: java.lang.NullPointerException
	at com.atlassian.jira.workflow.validator.AbstractPermissionValidator.hasUserPermission(AbstractPermissionValidator.java:49)
	at com.atlassian.jira.workflow.validator.PermissionValidator.validate(PermissionValidator.java:46)
	at com.atlassian.jira.workflow.SkippableValidator.validate(SkippableValidator.java:52)
	at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1512)
	... 8 more
2015-02-23 14:21:06,104 http-bio-8090-exec-5 WARN oalbertini 861x478353x1 1h891ap  /rest/analytics/1.0/publish/bulk [analytics.client.browser.PublisherResource] BrowserEvent property values should not be Collections or Maps. name=servicedesk.page.view.agent.session, properties={count=5, path=[queues, queues/issue, queues/issue, queues/issue, queues/issue], sdVersion=2.2.0}

 

someone can help me plz ? THX !

1 answer

For us it works better via SQL:

def stringvalue = sql.firstRow("SELECT concat(lower(p.pkey),'/',vform.key) as value FROM jiraissue i , project p, issuetype t ,  AO_54307E_VIEWPORT vport, AO_54307E_VIEWPORTFORM vform WHERE p.id = i.project 	AND i.issuetype = t.id	AND i.project = vport.project_id AND vport.id = vform.viewport_id AND	vform.issue_type_id = t.id AND i.id = $issue.id;");
	
	DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
	def serviceType = "customfield_10000"
	customFieldTarget = customFieldManager.getCustomFieldObject(serviceType);
	if(stringvalue.value != "null"){
		def requestType = customFieldTarget.getCustomFieldType().getSingularObjectFromString(stringvalue.value)
		customFieldTarget.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customFieldTarget), requestType),changeHolder);
	}

After that, reindex the issue.

 

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 Mar 09, 2018 in Jira Service Desk

E.L. Fridge's take on education, Jira Service Desk, and creative Jira use cases

...word of mouth, so by 2016, we were working with several other entities on campus to implement Jira Service Desk . The Atlassian motto of “for every team” has really come true for us in this case. We...

970 views 2 14
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