Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update fields via script (listeners)?

NewByatl
Contributor
June 14, 2021

Hello, im trying to update filed to null value with listeners. Aftet update logs shows me nothing, no errors, but nothing is changed, field still not empty. What wrong with my script?

 

short description of script: if value 1 == error or customization; then value 2 = null, then value 3 = null and ect

 

type fields:

value 1 - (type: Deviniti [Dynamic Forms] - Dynamic Select)

value 2 3 and others ( types: Deviniti [Dynamic Forms] - Dynamic Select, multiple select list, text field)

 

Script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = event.issue


def field_1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Тип запроса")
def field_2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Пояснение к ЭФ")

def newValue = issue.getCustomFieldValue(field_1)

if (newValue =="Ошибка"){

field_2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field_2), null), new DefaultIssueChangeHolder())
}else if (newValue =="Настройка"){

field_2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field_2), null), new DefaultIssueChangeHolder())
}

image-2021-06-15-00-05-56-366.png

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2021

My suspicion is that you can't update Devinity Dynamic Form fields like that. This is okay for most regular custom fields.

With Dynamic form, what you actually want to use their own API: https://deviniti.com/support/addon/server/dynamic-forms/latest/bundled-fields-java-api/

I have no experience with that. I just found the reference page.

NewByatl
Contributor
June 16, 2021

All right, thnk u! I'll rebuild script and back soon. 

PS: few days ago devinity custom field was hidden by regular script. I think something wrong with current script, cause i cant change even regular textfields :(

NewByatl
Contributor
June 16, 2021

I made it. Just needed to use next if (newValue.toString() =="Ошибка")

Suggest an answer

Log in or Sign up to answer