Hello,
one of our external teams feeds weekly a file with values that we want to "synchronize" in a single select liste custom field.
This field is is deposited on our server in {server}/home/deposit.
The first step is to create the field with all the options. I know I can use the built-in script but if I can do that with console it's better for me.
The second step is to update weekly this field with the json file...
Does anyone have a sample script that would allow me to create and update this list from the file ?
Or can you just give me an example to bulk add options from a list that I can create directly in my script (to have a baseline) ?
last question, how can I "open" my jsonfile that is on my server on a scriptrunner console ?
Best regards,
David
Let me try to help.
Reading a file
You can read a file like this. The location should be accessible on the server where Jira is installed by the user running Jira.
File file = new File("/opt/jira/home/scripts/file.json")
Parsing JSON
Try this.
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(file)
//parsedJson will let you access your data
//parsedJson.id or parsedJson.name
To set custom field options
There are few possibilities. I would suggest take a look at this page and our script library where we have plenty of examples.
I hope it helps.
Ravi
Hello Ravi,
Thanks for your answer !
I try to reading the file with your method and it's work.
But when I try to parse my json file I have the following error :
2021-01-19 19:09:32,105 ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: groovy.json.JsonSlurper.parseText() is applicable for argument types: (java.io.File) values: [/home/user/depot/file.json] Possible solutions: parseText(java.lang.String), parse(java.io.File), parse([B), parse([C), parse(java.io.InputStream), parse(java.io.Reader) at Script21.run(Script21.groovy:8)
Here my code :
import groovy.json.JsonSlurper
File file = new File("/home/adminsii/depot/file.json")
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(file)
Do you know what is wrong ?
Best regards,
David
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.