Hi all,
I'm wondering if there was a way Scriptrunner could get an export for all of my customfields and their details such as:
a) Customfield Name
b) Customfield ID
c) Screen(s) used by customfield
d) Value(s)
e) Type of customfield
We are trying to consolidate our fields, and an export like this would save us MANY hours of time trying to retrieve it all. Any help is greatly appreciated!
Thanks,
Mike
The script given by the AI will give you the basics, but it is badly flawed.
It can't write the CSV out to anywhere that is not available to the server. The new File("/path/to/output/file.csv") is perfectly valid, but the path in there has to refer to a local file system on the server. If you've got a file share mounted on the server, that will work, but if not, you'll have to copy the results file down from the server somehow.
You'll also find that the {fieldType} contains utter garbage if you were to use this script. The AI does not understand that fieldType is an object, which would be printed as an encoded string of characters. You probably want a more human representation, to which I would add .getName() to get what you see in the UI.
For the output, you could run the script in the SR console, and copy/paste the results it gives you on-screen. Instead of writing to a file, you could just put a "log" statement in - the console will display all of those when it runs.
As for the two lines the AI didn't even try, I have to ask if it's worth it. A list of all custom fields is useful for evaluating a migration, but the screens it is used on, and the possible content (of select type fields) is not going to tell you much.
I would be far more interested in how much a field has been used. (Also, the code for getting the screen usage is horribly complex - done properly, you'll need to check screens, field context, and field configuration, and cross reference the three against each project and issue type)
Hi again @Nic Brough -Adaptavist-
I don't have access to the server backend and we don't have a file share on the server either, so it sounds like I'd need to display any results I'm able to pull from a script within the SR console and then paste them into an excel file myself.
Our main goal is to have a list of details of each customfield we have within our instance.
The main reason for seeing which screens a particular customfield is on, is to see which team(s) within our instance are using a specific customfield. If pulling a different data point; such as the issue type(s) a customfield is used within would be simpiler, that would provide us with the same data we seek.
How would I parse the Ai provided code in order to display all the needed details for each customfield?
Like this?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
def customFieldManager = ComponentAccessor.customFieldManager
// Get all custom fields
List<CustomField> customFields = customFieldManager.getCustomFieldObjects()
// Retreive each customfield
customFields.each { CustomField customField ->
def fieldName = customField.name
def fieldId = customField.id
def fieldType = customField.getCustomFieldType()?.getName() ?: ""
// Write the customfields to the console
log << "\"${fieldName}\",\"${fieldId}\",\"${fieldType}.getName()\"\n"
}
Thanks again for all the help!
~mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The AI really isn't even close. It think it's close, but it's not.
Here's a basic script that'll return most of what you're after:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, thanks @Ken McClean - that's far better.
I have to admit I was thinking in HAPI when I read the terrible AI script - this makes scripting a lot easier and shorter, and it's closer to what the AI took a guess at. You can do stuff like "def fieldcontent = issue.getCustomFieldValue('My field')" without needing any imports or having to "get" the custom field.
@Michael - it's very complex to explore where a field is really used, so my instinct is to ask what would be most useful to you during your analysis and focus on one of the routes, not try to cross reference all of them.
What is most representative of your current setup? You said screens already, but my instinctive go-to is "what data have we got in them?", so I want to check if screens is best for you if you're going to keep it simple.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Nic Brough -Adaptavist- and @Ken McClean
Sorry for the delayed response. @Ken McClean although that script seems to not have any issues with it, the console just hangs after I input that script. Maybe 10 minutes after the script starts, the tab does show about 301 logs - but I can't even click on the "logs" tab without the tab going black and showing an infinite "loading" circle. Is there a way to better parse the information so it doesn't make Jira "chug"?
@Nic Brough -Adaptavist-The main reason why we wanted to retreive the screens was because we include the name of each team who uses a screen within the name of that screen; hence basically grabbing the team(s) that use each customfield. So I guess I need to change my requirements to be a little less vague. (Maybe finding the issue type a customfield is associated with would be easier?)
Main Goal:
To create a list of all customfields within our Jira Instance that contains the following data for each individual customfield:
a) Customfield Name
b) Customfield ID
c) Team using customfield (Issue Type maybe?)
d) Value(s) available within the customfield
e) Type of customfield (IE: Select List [Single], Select List [Multi], etc)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Michael ,
Welcome to Atlassian Community!
Please find the below script to achieve your requirements.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
def customFieldManager = ComponentAccessor.customFieldManager
// Get all custom fields
List<CustomField> customFields = customFieldManager.getCustomFieldObjects()
// Create a CSV file to store the custom field details
def csvFile = new File("/path/to/output/file.csv")
// Write the CSV header
csvFile << "Field Name,Field ID,Field Type\n"
// Iterate over each custom field and write its details to the CSV file
customFields.each { CustomField customField ->
def fieldName = customField.name
def fieldId = customField.id
def fieldType = customField.getCustomFieldType()?.getName() ?: ""
// Write the custom field details to the CSV file
csvFile << "\"${fieldName}\",\"${fieldId}\",\"${fieldType}\"\n"
}
csvFile.close()
Note :- Please change your side as your requirements link CSV path setup and all
Please Accept the answer If it helps you 😊
Regards,
Sanjen Bariki
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Sanjen Bariki
Would the save path for the CSV file be server side, or would that be for my local PC side? I'm trying to pull the data off the instance and house it on my local machine.
Thanks,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the CSV can only be saved server side, is there a way to display all my customfields and their details within the console so I can copy the needed data from the console to an Excel file myself on my end locally?
Thanks again,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm afraid this answer was given by an AI that does not understand the question or Atlassian software, and it's not going to be able to answer your follow-up questions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good to know, thank you. Is there a way for us to use scriptrunner in order to pull an export of the above?
Thanks again,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'll put something together for you, Michael. Give me a few minutes.
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.