Trying to create a sub-task based on a checklist field.
I have the following condition: cfValues['myfield']*.value.contains("myValue")
Returning the following error: ERROR - No such property: cfValues for class: Script1
The static checker returns this: The variable cfvalues is undeclared.
This worked on a server version I was previously using, but not on my current cloud version.
Did I do something wrong?
Thanks
Hi Alan,
There are significant differences between the Cloud and the Server versions of JIRA and how ScriptRunner works on the two platforms. You can read more here http://scriptrunner-docs.connect.adaptavist.com/jiracloud/ and here http://scriptrunner-docs.connect.adaptavist.com/jiracloud/migrating.html
For this particular question, the equivalent condition will look something like this:
// Get the field ids def fields = get('/rest/api/2/field') .asObject(List) .body as List<Map> def myFieldId = fields.find { it.name == "myfield" }.id return issue.fields[myFieldId]?*.value.contains('myValue')
Hope that helps,
Jon
Hey Jon....sorry for the delay.
Using that script gives me the following error
2017-02-06 22:40:19,707 ERROR - Class: com.adaptavist.sr.cloud.workflow.CreateSubtask, Config: [className:com.adaptavist.sr.cloud.workflow.CreateSubtask, uuid:2a268983-c96a-4f4f-a42f-3e04804d17db, description:BitBucket Request, condition:// Get the field ids def fields = get('/rest/api/2/field') return issue.fields[myFieldId]?*.value.contains('bitbucket'), summary:New BitBucket Access Request!, issueTypeId:10202, executionUser:INITIATING_USER, additionalCode:]
Any thoughts on this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan,
Looks like I got my Groovy slightly wrong - it should be:
return issue.fields[myFieldId]*.value?.contains('myValue')
Thanks, Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jon:
Using this gives me a new error below:
groovy.lang.MissingPropertyException: No such property: issue for class: Script1 at Script1.run(Script1.groovy:8) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:22) at ScriptExecution1_groovyProxy.run(Unknown Source)
Static checker says: "The variable 'issue' is undeclared" at line 8 column 8.
Thanks a lot for your time and help with this!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan, are you running that from the Script Console or have you set it as the condition on a post function?
It won't work in the Script Console as the code expects there to already be an issue in the execution context...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Jon: I did run it from the console, however the static checker from the condition dialogue box is still saying "The variable 'issue' is undeclared" at line 8 column 8
I'll try to execute the post function anyways to see if it goes through.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan, there are a couple of problems with the static type checking that we're close to having a fix for, so sometimes the messages are misleading. Did this code work in the post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Jon Bevan _Adaptavist_ ,
I also have the same requirement, the above code is not working for us. Can you please help here? I see the errors below :
Thanks,
Swathi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swathi,
Those particular "errors" are actually just limitations of our type-checking system.
You can just ignore them, or make them go away by using the following code:
List<Map<String, Object>> fields = get("/rest/api/2/field")
.asObject(List)
.body
String myFieldId = fields.find { it.name == "myfield" }.id
return (issue.fields[myFieldId] as List<Map>)*.value?.contains('myValue')
Thanks,
Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks so much it worked for a checklist custom field.
I am trying the similar code on a single select list field "Department" but it is failing , can you tell me what Am I doing wrong?
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def input1CfId = customFields.find { it.name == 'Department' }?.id
def input1 = issue.fields[input1CfId] as String
if (input1 == 'Operations & Maintenance')
{
return
}
When I run this , I expected a sub task to be created. I see that the run is successful with message the following message :
2018-02-16 12:55:20.267 INFO - Serializing object into 'interface java.util.List' 2018-02-16 12:55:20.290 INFO - GET /rest/api/2/field asObject Request Duration: 555ms 2018-02-16 12:55:20.328 INFO - Condition didn't eval to true, exiting
Can you tell me why it din't create a sub task? Appreciate your help here.
Thanks,
Swathi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swathi,
I think you need to use:
def input1 = issue.fields[input1CfId].value as String
Thanks,
Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Appending value also dint help . However, when I tried some script in console i see that I am able to fetch the value...
def issueKey = 'HR-39'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
return result.body.fields.customfield_10088.value
}
else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
Same script is not working when I place in post function. Can you help me in converting the above code to work in post function?
Thanks,
Swathi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted]
The script will fail if there is no value in that field, so you'll need to use the safe navigation operator:
def input1 = issue.fields[input1CfId]?.value as String
If that doesn't resolve the problem then I'll need to see the specific error messages you're seeing.
Thanks,
Jon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
PS - I have verified that the field that I am using DOES exist, and I have done a re-index for good measure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.