I have created a custom field "customer name" which is of type "Select list (multiple choices)". I have a list of 1000 customer names to add to this list. I am sure adding it manually is the slow route. Is there a way to add this programmatically or through script. We have scriptrunner installed in our Jira cloud. Can I make use of that to add of these 1000 names to the custom field ?
--Sunray
Hi @Ashwin Balakrishnan
I assume that you use something to manage your list of customer names and want to be able to easily keep the list in sync when a new customer needs to be added or even a name changed.
Whilst you could manage this with a select list (multiple choices) let me introduce a new option in Cloud to you which is to use the custom field of asset.
This is defined at https://developer.atlassian.com/cloud/assetsapi/rest/ but here is a quick overview for you to consider if this is suitable for you.
1. Define an asset type in which you are going to store your options.
2. Create an asset of the asset type defined in step 1.
3. Make sure you have a list of options with a permanent id and load these in to your asset type defined in step 2.
3. Add the asset to which ever screens you want to use it on.
Regards
Phill
Hi @Phill Fox
Thanks for replying. I created a custom field with type as "Asset" . I think added this custom field to few screens. When I go to "contexts and default value", I get an option "Edit filters". When I click on "Edit Filters", it is asking "Choose a type".
Is there a way I can create a filter with all the customer names so I can choose this filter so these names show up in the field while creating a ticket ?
The use case you describe is one of the options for which assets were developed. The important part to do is to preload your asset list in the system so that you can define the filter to select the options you want to display.
You will only need to define a filter if you have different lists of assets and need to distinguish between them.
Once you have your list loaded you can link multiple entries to an issue. See
https://www.dropbox.com/s/jakkfdsk96ez8cd/Screenshot%202020-03-09%2021.31.45.png?dl=0
for an example with the list of UK Universities.
How can I preload the asset list in the system ?
Hi
You can do it in bulk using the instructions at https://developer.atlassian.com/cloud/assetsapi/rest/#api-asset-bulk-put
this requires you to fill in some details in a curl command with the details for your asset. This will allow you to add 25 at a time so it is best to do this programmatically.
This is an example of the command
curl --request PUT \ --url '<yourhost>/rest/assetapi/asset/bulk' \ --header 'Content-Type: application/json' \ --data '{ "putRequest": [ { "origin": { "appKey": "com.myasset.app", "originId": "5-113-51143-2032" }, "label": { "value": "MacBook Pro 15\" 2016" }, "type": { "appKey": "com.myasset.app", "originId": "5-113-51143-2032" }, "assignee": { "accountId": "27505:c73cd17f-ae93-4f10-911c-d754d02420be", "email": "test@example.com" }, "fields": [ { "fieldId": "RAM", "value": "8GB DDR4 2400MHz" } ] } ] }'
A couple of things to notice here.
com.myasset.app is a reference to your appKey and can be any value.
originid is a UUID to uniquely identify your app and the type definition must match the settings defined in your assettype.
label is what will be seen in the interface
assignee and fields are optional.
Hi,
I used the following code to add the asset
curl -X PUT \https://<<my jira url>>/rest/assetapi/asset \-H 'Content-Type: application/json' \-H 'cache-control: no-cache' \-d '{"origin": {"appKey": "my-app","originId": "customername1"},"label": {"value": "customername1"}}'
When I ran this curl , I am able to add the asset. The "customername1" shows up under the custom field that I had created. In a ticket, I can choose this asset. However, when I run jql query, I am not able to search for it. Any reason why?
My custom field is "customer asset" so I am trying to do the jql search as
"Customer Asset" = "customername1" but the result is empty.
Here is a script that can be run in the Script Console to populate a select list:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.customfields.manager.OptionsManagerimport com.atlassian.jira.issue.customfields.option.Optionimport com.atlassian.jira.issue.customfields.option.Optionsimport com.atlassian.jira.issue.fields.config.FieldConfigimport com.atlassian.jira.issue.fields.config.FieldConfigSchemeimport com.atlassian.jira.issue.fields.CustomFieldCustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Toppings")[0];List<String> values = ["Pepperoni","Sausage","Onions"]if (customField != null) { List<FieldConfigScheme> schemes = customField.getConfigurationSchemes(); if (schemes != null && !schemes.isEmpty()) { FieldConfigScheme sc = schemes.get(0); Map configs = sc.getConfigsByConfig(); if (configs != null && !configs.isEmpty()) { FieldConfig config = (FieldConfig) configs.keySet().iterator().next(); OptionsManager optionsManager = ComponentAccessor.getOptionsManager(); Options options; int nextSequence; for(int i=0;i<values.size();i++) { options = optionsManager.getOptions(config); nextSequence = options.isEmpty() ? 1 : options.getRootOptions().size() + 1; optionsManager.createOption(config, null, (long) nextSequence, values[i]); } } }}
I ended up using Jira API https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest%2F&utm_medium=302#api-rest-api-3-customField-fieldId-option-get
to add options to the custom field.
--Ashwin
Thanks
It looks like you're new here. Sign in or register to get started.