/** This example script console script shows how to bulk import custom field values . * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */// Specify the name of the custom field belowdefcustomtFieldName=''// Get the Custom field to get the option value fromdefcustomField=get("/rest/api/2/field").asObject(List).body.find{(itasMap).name==customtFieldName}asMap// Check if the custom field returns a valid field and is not nullassertcustomField!=null// Get all contexts for the custom fielddefgetContexts=get("/rest/api/3/field/${customField.id}/context").asObject(Map)// Check if we fetched the custom field contexts correctlyassertgetContexts.status>=200&&getContexts.status<300// Get the Id for the default contextdefdefaultContextId=getContexts.body.values[0].id;// Provide an array for each field option which has a key value pair of "value":"OptionValueHere"defoptionsArray=[// Replace with real option values below["value":"Option 1"],["value":"Option 2"],["value":"Option 3"]]// Set the new custom field optionsdefaddCustomFieldOptions=post("/rest/api/3/field/${customField.id}/context/${defaultContextId}/option").header('Content-Type','application/json').body(options:optionsArray).asJson()// Validate that the custom field options were added correcltyassertaddCustomFieldOptions.status>=200&&addCustomFieldOptions.status<300// Log out what field was updatedlogger.info("The custom field named ${customtFieldName} has been updated with the new values provided")
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.