Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 !

2 answers

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.

 

I just want to mention that the first substring is not the project key but the portal key. The portal key matches the project key if the project key was never changed. Using AO_54307E_VIEWPORT.KEY is the correct solution.

What about this?
issue.getProjectObject().getOriginalKey()

There isn't a better way of getting the key of the request type's name?? You have to search the database in order to get that? 

We have the problem of many issues comming form emails and we need to triage them based on some parameters and we need to set the correct Customer Request Type for each one. We do that with code because it isn't always strightforward. 

Does anyone know why this isn't as simple as ".getKeyFromName()" kind of function?

Is there an Atlassian issue where I can vote to extend the api so that there is a better way of getting (and setting) the CRT key?

Cheers,

Marina

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Announcing Mindville Insight is now part of Jira Service Management!

Hello Community! We’re excited to announce that Mindville Insight’s asset and configuration management capabilities will now be integrated into Jira Service Management Premium and Enterprise plan...

752 views 12 15
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you