Hi everyone.
I hope some could help with my issue on the script below. Every time I do a test run, the validation condition always end up on the last ELSE block; and it is not process the rest of the code – i.e., the update on 2 fields.
My script is below…
// test to update Resolver group and Functional area
def issueKey = ‘TEST-37’
// Fetch the issue object from the key
def result = get(“/rest/api/2/issue/${issueKey}”)
.header(‘Content-Type’, ‘application/json’)
.asObject(Map)
.body
.fields
Hey Zaldy,
Looks like the issue is on defining the customfield for your functional area and resolver group. Hope this helps.
Not sure what types of fields you are using for your parent/child and functional/resolver, but here is my version for ScriptRunner for Jira Cloud.
For the main parent/child field, I used the custom field “Select List (cascading)”, and the other func_area and resol_grp is “Text Field (single line)”
Thank you very much for your sample script. I really appreciate experts helping a novice like me.
The I copy-pasted your script in the Console and replaced the custom field IDs with the real ones.
But it had an error on the update = put statement block.
The block is….
def update = put(“/rest/api/2/issue/${issueKey}”)
.header(“Content-Type”, “application/json”)
.body([
fields: [
“customfield_10221” : func_area?.toString(), // Field ID of func_area
“customfield_10222” : resol_grp?.toString() // Field ID of resol_grp
]
])
.asString()
Where customfield_10221 is the Functional area field ID, and customfield_10222 is the Resolver group field ID.
The log has this error message:
Serializing object into ‘interface java.util.Map’
GET /rest/api/2/issue/TEST-32 asObject Request Duration: 520ms
Parent value: Application (Non-SAP)
Child value: Jira
PUT /rest/api/2/issue/TEST-32 asString Request Duration: 438ms
PUT request to /rest/api/2/issue/TEST-32 returned an error code: status: 400 - Bad Request
body: {“errorMessages”:,“errors”:{“customfield_10221”:“Specify a valid ‘id’ or ‘name’ for Functional area”,“customfield_10222”:“Specify a valid ‘id’ or ‘name’ for Resolver group”}}
Serializing object into ‘interface java.util.Map’
Functional area: Technology
Resolver group: Jira Administrator Update response: status: 400 - Bad Request
body: {“errorMessages”:,“errors”:{“customfield_10221”:“Specify a valid ‘id’ or ‘name’ for Functional area”,“customfield_10222”:“Specify a valid ‘id’ or ‘name’ for Resolver group”}}
I know that the custom field IDs are correct as I double checked it in the Jira Settings.
But as you can see, it returned a 400 – Bad Request in the update.
Might something trivial that I forgot to change/update?
I tried your version, basically copy-pasted it to the script console. Then I updated the def issueKey = “XXXXX” with “TEST-37”; along with other variables bearing “XXXX” replacing it with values applicable to our Jira project.
However, I got warnings on lines 16, 17, and 18. Something like No such property: customfield_10220 for class: java.lang.Object @ line 16, column 27.
I ignored the warnings and run the script. But the put statement threw an error.
Serializing object into ‘interface java.util.Map’
GET /rest/api/2/issue/TEST-37 asObject Request Duration: 670ms
Parent value: Application (SAP)
Child value: OpenText
PUT /rest/api/2/issue/TEST-37 asString Request Duration: 353ms
PUT request to /rest/api/2/issue/TEST-37 returned an error code: status: 400 - Bad Request
body: {“errorMessages”:,“errors”:{“customfield_10221”:“Specify a valid ‘id’ or ‘name’ for Functional area”,“customfield_10222”:“Specify a valid ‘id’ or ‘name’ for Resolver group”}}
Serializing object into ‘interface java.util.Map’
Functional area: Corporate
Resolver group: SAP Finance Management
Update response: status: 400 - Bad Request
body: {“errorMessages”:,“errors”:{“customfield_10221”:“Specify a valid ‘id’ or ‘name’ for Functional area”,“customfield_10222”:“Specify a valid ‘id’ or ‘name’ for Resolver group”}}
I’m pretty sure the customfield IDs are correct and the fields are visible on the screen.
I also tried replacing the “customefield_10221” with the actual field name as “Functional area”. But still resulted to errors.
What am I doing wrong?
Btw, tried replying through email but was rejected and bounced back.
Hey @Zaldy , sorry I missed your responses and Happy New Year to you and family too!
Maybe it would be easier if we have a call together to understand better, drop an email to customersuccess@scriptrunnerhq.com and mention “Sean to pick up” and my team will know its for me. I’m happy to help and lets go check it out together.
On to your responses;
If it is a direct copy, Line 16, 17, 18 would be: (mine shows the same error but it works).
Not sure if you used the same Select List (cascading) for that field as I’ve set up with exactly what options can be selected for Parent and Child. The XXXX uses the same parent customfield id.
For the other issue:
def update = put("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.body([
fields: [
"customfield_XXXXX" : func_area?.toString(), // Field ID of func_area
"customfield_XXXXX" : resol_grp?.toString() // Field ID of resol_grp
]
])
.asString()
My field uses Text Field (single line) to fill in the details based on the selection from parent field. If you are using a different type of customfield, this may need to change to something else.
I think you’re right that the warnings at line 16,17, & 18 can be ignored.
I’ll modify my PUT statement to fit the intended fields. FYI, the Functional area and Resolver group fields are both Select List (single choice). And I thought the “?.toString()” syntax will also applicable. Anyway, I do some trials on syntax that will work on hte PUT statement for Select List (single choice) field.
If I can’t make work, I will setup a Teams or Zoom meeting with you for tomorrow. I work in Melbourne, Australia. If our normal office hours doesn’t work with your time, I could also have a meeting with you even after office hours from my home. Let me know what time (Melbourne time) suits you.
Hey @Zaldy , I’m on +8 UTC which is just 3 hours behind Melbourne. Happy to jump into a call with you anytime after 1pm (Melb). I’ve sent you a “Personal Message” with my booking link.
Click into the 3 lines / Hamburger Icon at the top right.
You been very helpful and with very very very long patience dealing with me. I really appreciate your kind assistance.
With the modification you suggested, I was able to successfully update the issue through the Console. I then did further modifications to have the script in the Listener. But strangely, the Functional area and Resolver group were not being updated.
The log is like this…
2024-01-09 05:11:43.659 INFO - Serializing object into ‘interface java.util.List’
2024-01-09 05:11:43.661 INFO - GET /rest/api/2/field asObject Request Duration: 566ms
2024-01-09 05:11:44.280 INFO - Serializing object into ‘interface java.util.List’
2024-01-09 05:11:44.282 INFO - GET /rest/api/2/field asObject Request Duration: 617ms
2024-01-09 05:11:44.869 INFO - Serializing object into ‘interface java.util.List’
2024-01-09 05:11:44.872 INFO - GET /rest/api/2/field asObject Request Duration: 586ms
2024-01-09 05:11:45.489 INFO - Serializing object into ‘interface java.util.List’
2024-01-09 05:11:45.493 INFO - GET /rest/api/2/field asObject Request Duration: 617ms > 2024-01-09 05:11:45.515 INFO - Parent value: [] > 2024-01-09 05:11:45.516 INFO - Child value: []
2024-01-09 05:11:46.149 INFO - PUT /rest/api/2/issue/TEST-39 asString Request Duration: 630ms
Notice the Parent value and the Child value of the cascading field came out as blank.
To extract the Parent and Child values, I have the same code as in Console…
// identify the source field
def customFieldcategory = result.customfield_10220
def Category_parent = customFieldcategory?.value
def Category_child = customFieldcategory?.child?.value
Hey @Zaldy , that is odd indeed. I’m not able to identify where or how to help currently as we may need to investigate further into the logs and/or other details, i’d recommend to create a Support Ticket with our Support Engineers to take a deeper look together with you.