# How do I update 2 custom Jira fields at a time?

**URL:** <https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408>\
**Category:** Scripts\
**Tags:** cloud, jira, listener\
**Created:** [December 11, 2023, 4:30am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408 "2023-12-11T04:30:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaldy](https://avatars.discourse-cdn.com/v4/letter/z/779978/32.png) [@Zaldy](https://forum.library.adaptavist.com/u/Zaldy)\
**Post date:** [December 11, 2023, 4:30am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/1 "2023-12-11T04:30:02Z")

</div>

Hi all,

Thanks for reading my query. And hope someone could help me with my trivial question…  
I got 3 custom fields:

- Issue category - which is a cascading field (customfield\_10220)
- Functional area - single picklist (customfield\_10221)
- Resolver group - single picklist (customfield\_10222)

Based on the values selected in Issue category field, I want to populate the Functional area and Resolver group fields. I use IF-ELSE-THEN condition statements, but the THEN code block is throwing an error.

Can someone please help with my script below?

def customFields = get(“/rest/api/2/field”)  
.asObject(List)  
.body  
.findAll { (it as Map).custom } as List

//this was added by the scriptrunner cloud example as a way to check the listener is only applied to the correct project  
def projectKey = “TEST”  
if (issue == null || ((Map) issue.fields.project).key != projectKey) {  
logger.info(“Wrong Project ${issue.fields.project.key}”)  
return  
}

def CategoryCfId = customFields.find { it.name == ‘Issue category’ }?.id  
def FuncAreaCfId = customFields.find { it.name == ‘Functional area’ }?.id  
def ResolverCfId = customFields.find { it.name == ‘Resolver group’ }?.id  
def IssueCategory = issue.fields[CategoryCfId] as Map  
def Resolver = issue.fields[FuncAreaCfId] as Map  
def Resolver = issue.fields[ResolverCfId] as Map  
logger.info(“Current Resolver group: ${Resolver.value}”)

def category = issue.fields.customfield\_10220[‘value’].toString()  
def subcategory = issue.fields.customfield\_10220[‘child’][‘value’].toString()

logger.info (“Sub-category: ${subcategory}”)  
if (category == “Non-SAP” && subcategory == “Jira”) {  
Func\_area = “Technology”  
Resol\_grp = “Jira Administrator”  
} else if (category == “Technology” && subcategory == “Hardware”){  
Func\_area = “Technology”  
Resol\_grp = “IT Service Desk”  
}

put(“/rest/api/2/issue/${issue.key}”)  
.header(“Content-Type”, “application/json”)  
.body([  
fields: [  
“Resolver group” : Resol\_grp  
“Functional area” : Func\_area  
]  
])  
.asString()  
}

Regards,

---

<div class="post-metadata">

**Author:** ![kcwong](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kcwong](https://forum.library.adaptavist.com/u/kcwong)\
**Post date:** [December 12, 2023, 11:08am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/2 "2023-12-12T11:08:58Z")

</div>

> [@Zaldy](#):
>
> but the THEN code block is throwing an error.

And the error is? Which line?

---

<div class="post-metadata">

**Author:** ![Zaldy](https://avatars.discourse-cdn.com/v4/letter/z/779978/32.png) [@Zaldy](https://forum.library.adaptavist.com/u/Zaldy)\
**Post date:** [December 13, 2023, 10:05pm UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/3 "2023-12-13T22:05:17Z")

</div>

Hi kcwong,

the error is on at line 38, column 25

> 2023-12-13 22:00:38.363 ERROR - startup failed:  
> Script1.groovy: 38: Unexpected input: ‘(“/rest/api/2/issue/${issue.key}”)\r\n .header(“Content-Type”, “application/json”)\r\n .body([\r\n fields: [\r\n “Resolver group” : Resol\_grp\r\n “Functional area”’ @ line 38, column 25.  
> “Functional area” : Func\_area  
> ^  
> It is the second field I wanted to update, on this code block:  
> put(“/rest/api/2/issue/${issue.key}”)  
> .header(“Content-Type”, “application/json”)  
> .body([  
> fields: [  
> “Resolver group” : Resol\_grp  
> “Functional area” : Func\_area //\<- thowing an error  
> ]  
> ])

Thanks for your reply.  
Cheers.,

---

<div class="post-metadata">

**Author:** ![kcwong](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kcwong](https://forum.library.adaptavist.com/u/kcwong)\
**Post date:** [December 13, 2023, 10:57pm UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/4 "2023-12-13T22:57:42Z")

</div>

I think you have an array but no comma between the elements.

```auto
fields: [
“Resolver group” : Resol_grp <-- No delimiter here
“Functional area” : Func_area
]

```

---

<div class="post-metadata">

**Author:** ![Zaldy](https://avatars.discourse-cdn.com/v4/letter/z/779978/32.png) [@Zaldy](https://forum.library.adaptavist.com/u/Zaldy)\
**Post date:** [December 14, 2023, 12:36am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/5 "2023-12-14T00:36:04Z")

</div>

Thanks, @kcwong ,

Added a comma as suggested. The warning icon (exclamation point in yellow triangle) disappeared. But another warning came up at the very last line:  
 ![scriptrunner5](https://us1.discourse-cdn.com/flex019/uploads/adaptavistlibrary/original/1X/a10df573427de1af7e80d9a8d2f1185eaed05fe7.png)

And with it, an error:

> 2023-12-14 00:28:56.808 ERROR - startup failed:  
> Script1.groovy: 42: Unexpected input: ‘([\r\n fields: [\r\n “Resolver group” : Resol\_grp,\r\n “Functional area” : Func\_area\r\n]\r\n ])\r\n .asString()\r\n}’ @ line 42, column 1.  
> }  
> ^
> 
> 1 error
> 
> 2023-12-14 00:28:56.812 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null

---

<div class="post-metadata">

**Author:** ![kcwong](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kcwong](https://forum.library.adaptavist.com/u/kcwong)\
**Post date:** [December 14, 2023, 12:50am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/6 "2023-12-14T00:50:52Z")

</div>

Your variables Func\_area and Resol\_grp are defined in the scope of the if statement, you can’t use them outside.

---

<div class="post-metadata">

**Author:** ![Zaldy](https://avatars.discourse-cdn.com/v4/letter/z/779978/32.png) [@Zaldy](https://forum.library.adaptavist.com/u/Zaldy)\
**Post date:** [December 14, 2023, 2:36am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/7 "2023-12-14T02:36:43Z")

</div>

Hi @kcwong ,

I really appreciate your quick response.

How do you suggest I achieve this? I basically wanted to first validate the values of Issue category and sub-category selected by the user on create or edit event using an IF/ELSE statement (I don’t know how to use SWITCH statement). Then once validated, at the end I want to automate the population of Functional area and Resolver group, hence the code is outside of IF/ELSE statement.

I would appreciate your kind help and guidance.

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/adaptavistlibrary/original/1X/ceb18adf14fa58b4c6de03aa69ada8b07359620c.png) [@system](https://forum.library.adaptavist.com/u/system)\
**Post date:** [June 11, 2024, 2:37am UTC](https://forum.library.adaptavist.com/t/how-do-i-update-2-custom-jira-fields-at-a-time/408/8 "2024-06-11T02:37:21Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
