You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于Jira的'Bulk Fix Resolutions'脚本批量更新自定义字段值?

Adapting the 'Bulk Fix Resolutions' Script for Custom Field Bulk Updates

Great question! Adapting that script to target a custom field instead of the resolution status is totally doable—let’s walk through the key adjustments you’ll need to make:

1. Grab Your Custom Field’s Unique Identifier

First up, you need the ID or key of your target custom field. Here’s how to get it:

  • Head to Jira Settings → Issues → Custom Fields
  • Find your field, click the three-dot menu → View Details
  • Copy the Custom Field ID (it’ll look like customfield_12345)
  • Alternatively, use Jira’s REST API to list all fields:
    GET /rest/api/3/field
    
    Search the response for your field’s name to grab its id or key.

2. Swap Resolution Field Logic for Custom Field Logic

The original script centers on Jira’s built-in resolution field—you’ll need to replace that with code targeting your custom field. Here’s a typical before/after example:

Original Resolution-focused snippet:

def resolution = ComponentAccessor.resolutionManager.getResolutionById(resolutionId)
issue.setResolution(resolution)

Updated Custom Field snippet:

// Replace with your actual custom field ID
def customFieldId = "customfield_12345"
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(customFieldId)

// Adjust based on your custom field's type
if (customField.type.name == "Select") {
    // For single-select fields: fetch the target option object
    def targetOption = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issue))
        .find { it.value == "Your Desired Value" }
    issue.setCustomFieldValue(customField, targetOption)
} else if (customField.type.name == "Text Field") {
    // For text fields: directly set the string value
    issue.setCustomFieldValue(customField, "Your Custom Text")
}

3. Update the Script’s Input/UI (If Using ScriptRunner)

If this is a ScriptRunner bulk script, the original likely has a UI dropdown for selecting a resolution. You’ll need to tweak this to let users input or select the custom field value:

  • Replace the resolution dropdown with one populated by your custom field’s options (for select-type fields)
  • Add a text input box if your custom field accepts free-form text
  • Update the script’s parameter definitions to map to the new UI elements

4. Handle Field Type Specifics

Different custom field types need different handling—don’t skip this:

  • Single/Multi-select: You must pass an Option object (not just a string)
  • Text/Number/Date: You can pass the raw value (string, integer, Date object)
  • User Picker: Pass a ApplicationUser object (retrieve via ComponentAccessor.userManager.getUserByName("username"))

5. Test Before Going Bulk

Never run a modified script on a large batch of issues first:

  • Test with 1-2 test issues to confirm the custom field updates correctly
  • Double-check permissions (ensure the script has edit access to both the field and the target issues)
  • Verify the field is available in the context of all issues you’re targeting

内容的提问来源于stack exchange,提问作者user2055729

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:01:37