Forums

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

How to change json value (groovy, automation, scriptrunner, regex)

Petr AST
Contributor
April 14, 2022

Dear Community!

Trying to test scripts in Jira and I ran into a problem, is it possible to change the tag values ​​already in the custom field?

Field:

 

"tags":[
{"tag":"TAG1","value":"VALUE1"},
{"tag":"TAG2","value":"VALUE2"},
{"tag":"TAG3","value":"VALUE3"},
{"tag":"TAG4","value":"VALUE4"}]

 

And you need to put certain customfields values instead of json values.
Is it possible via automation or scriptrunner os something else? 

 

Thanks a lot!!

 

1 answer

1 vote
Mark Segall
Community Champion
April 15, 2022

Hi @Petr AST - Can you please provide a little more context? If I understand correctly, you have a field called Tags.  What would help me better understand:

  • What type of field is this?
  • When you say, change the values, are you trying to change the values across a number of issues or modify the custom field itself?
Petr AST
Contributor
April 16, 2022

Hi @Mark Segall!

Thanks for you reply!

There is a customfield, which already contains a json value from integration.

I need to change the values in this field so that the values can be taken from customfield_1, customfield_2 and customfield_3 for example:

"tags":[
{"tag":"TAG1","value":"customfield_1.value"},
{"tag":"TAG2","value":"customfield_2.value"},
{"tag":"TAG3","value":"customfield_3.value"},
{"tag":"TAG4","value":"VALUE4"}]

Trying to test this script:

import groovy.json.JsonSlurper String jsonInputString = '''
{"tags":[
{"tag":"TAG1","value":"VALUE1"},
{"tag":"TAG2","value":"VALUE2"},
{"tag":"TAG3","value":"VALUE3"},
{"tag":"TAG4","value":"VALUE4"}]}
''' def json = new JsonSlurper().parseText(jsonInputString) json.tags[0].value = 1234 json.tags[1].value = 12345 println json

It returns me sucess result in logs

[tags:[[tag:TAG1, value:1234], [tag:TAG2, value:12345], [tag:TAG3, value:VALUE3], [tag:TAG4, value:VALUE4]]]

But how can I change this in the customfield itself in the issue, can't figure it out?

Like cozappz likes this

Suggest an answer

Log in or Sign up to answer