Hello , I am new to JIRA, can someone help me with my problem
I want to create a simple post function on JIRA Service Desk that automatically sets the Approvers Field based on the requestor's manager.
(i.e. if Requestor 1 creates a ticket, then the post function will read the property of requestor 1 and then finds the Manager and automatically set it to Approvers Field)
Any comments/suggestions are really appreciated. If you can also provide a sample post-function code for this one, that would be great.
Thanks!
You probably did some cleanup on your code in order to post ...
The relevant part of the error is this:
java.lang.NullPointerException
at Script75$_run_closure1.doCall(Script75.groovy:34)
That means that on line 34 of your script (a in-line scripts get automatic names like Scriptxx.groovy), something returned a null value that the compiler didn't know how to handle.
But the code you pasted only includes 31 lines total... so that makes it hard to identify the source of the issue.
But seeing as there is nothing directly wrong with your script, I would check to make sure that the run-as user for the jira app has permission to read/write to the 'C:/Users/name/Desktop' directory.
Thanks for the response, I really appreciate it.
I realize now that I did cut out some parts of the code before posting. Those parts however, were commented out and I still received this issue. I looked at line 34 of my script and the line of code that creates the nullpointerexception is
fileTest = fileTest.replaceAll(defaultIssueKey, issueKey);
From this, I can imagine that when I try to retrieve the issueKey, it's returning Null, so there's something wrong with how I am retrieving the issue key?
I did some further testing and if I were to replace 'issueKey' with a string like the following line of code
fileTest = fileTest.replaceAll(defaultIssueKey, "Test");
this code will run and write a text file to my desktop as I want it to, so I believe the error has nothing to do with the Jira app permissions.
Thanks again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Issue key appears to be retrieved from the query parameters.
So that means you should be calling your endpoint with <jirabaseurl>/rest/scriptrunner/latest/custom/WriteToDocument?issueKey=ABC-123
I always add validation to my query parameters for custom rest endpoints:
String issueKey = queryParams.getFirst("issueKey")
if(!issueKey){
return Response.serverError().entity([error: "Missing parameter: issueKey is required"]).build()
}
Note that getFirst("issueKey") is case sensitive, so WriteToDocument?issuekey=ABC-123 will not work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help, I realized that the error was caused by my query parameters being written incorrectly. I have one last question, how would I go about retrieving the issue's project name? Could I also retrieve this from the query parameters or is there a function that allows me to do it from within the script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, just like any other scriptrunner script, you have full access to all the Jira api. So, using the componentAccessor we can get te issueManager.
Something like this:
String issueKey = queryParams.getFirst("issueKey")
if(!issueKey){
return Response.serverError().entity([error: "Missing parameter: issueKey is required"]).build()
}
def issue = ComponentAccessor.issueManager.getIssueObject(issueKey)
if(!issue){
return Response.serverError().entity([error: "Bad parameter: issueKey was not found in jira"]).build()
}
def project = issue.projectObject
log.debug "Project Name = $project.name"
log.debug "Project Key = $project.key"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.