JSON を使用した詳細なフィールド編集
The More options additional fields should only be used if a field cannot be edited using Choose fields to set. This may be necessary for custom fields provided by other applications.
次の自動化アクションでは、フィールドを詳細に編集するためのフィールドが追加されます。
To access these fields, select More options when configuring the action. These additional fields require you to specify a valid JSON object using the format specified by the Jira REST API.
JSON のフォーマット
JSON オブジェクトには、属性 update
または fields,
などを含めることができます。
{
"update": {
"description": {
"set": "a new description"
},
"labels": [{
"add": "test-label"
}]
},
"fields": {
"summary": "woohoo! a new summary"
}
}
What's the difference between update and fields?
fields
はショートカットで、update
を set
操作によって呼び出します。上記の例では、説明フィールドとして set
を呼び出すことは description
を fields
セクションに含めることと等しくなります (例: {"fields": {"description":"a new description"}}
)。
update
は、複数の値を持つフィールドの既存のセットに値を追加する、および/または既存のセットから値を削除する場合に役に立ちます。たとえば set
演算子を使用して課題にラベルを追加すると、既存ラベルはすべて上書きされますが update
を使用すると、既存ラベルは削除せずにラベルが追加されます。
JSON の update
セクションと fields
の両方に同じフィールドが同時に表示されることはありません。
フィールドの編集時に発生する可能性のある問題
JSON が無効
入力した JSON が無効な場合、この警告が発生する可能性があります。JSON の構文を確認してから、もう一度お試しください。
JSON は有効だがスマート値が検証できない
この場合、JSON は有効ですが、フィールドに入力されたスマート値が検証できていません。ルールが実行されるまでスマート値を検証できないことが理由です。ルール実行の後に監査ログをチェックして、スマート値が想定どおりに機能していることを確認してください。
JSON が、検証できないスマート値で入力されている
この警告は、JSON のすべてをスマート値で入力しようとしたが、ルールが実行されるまでスマート値を検証できないことが理由で発生する可能性があります。ルール実行の後に監査ログをチェックして、スマート値が想定どおりに機能していることを確認してください。
JSON は有効でキーが欠落
この場合、JSON は有効ですが、更新またはフィールドのキーがないため、追加フィールドを解析できません。入力に、これらのキーを少なくとも 1 つ追加してからもう一度お試しください。
課題フィールドを参照する
カスタム フィールドは ID でなく名前で参照できます。以下の例では、同じフィールドが ID と名前で参照されています。
{
"fields": {
"customfield_10003": "the value I want to set",
"My Text Customfield": "this is the same field as above and using both causes an error"
}
}
名前で参照される場合、フィールドは大文字と小文字を区別しません。また、スペースはアンダースコアで置き換えることができます。
同じ名前のカスタム フィールドがある場合、またはカスタム フィールドの名前がシステム フィールドと同じ場合、カスタム フィールド ID を使用する必要があります。
サポートされているフィールドとオペレーション
If you’re creating or editing issues, you can query a project’s createmeta or an issue’s editmeta information to view supported fields and operations.
この 2 つのオペレーションのメタデータは、以下より取得できます。
GET /rest/api/3/issue/createmeta?projectKeys=<string>&expand=projects.issuetypes.fields
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
この JSON は、可能なオペレーションおよび値を含め、Additional fields
で使用できるすべてのフィールドを返します。
Consider the following response for createmeta:
{
"expand": "projects",
"projects": [
{
"expand": "issuetypes",
"self": "https://jira.atlassian.com/rest/api/2/project/10240",
"id": "10240",
"key": "JRA",
"name": "Jira (including Jira Work Management)",
"avatarUrls": {
"48x48": "https://jira.atlassian.com/secure/projectavatar?pid=10240&avatarId=17294",
"24x24": "https://jira.atlassian.com/secure/projectavatar?size=small&pid=10240&avatarId=17294",
"16x16": "https://jira.atlassian.com/secure/projectavatar?size=xsmall&pid=10240&avatarId=17294",
"32x32": "https://jira.atlassian.com/secure/projectavatar?size=medium&pid=10240&avatarId=17294"
},
"issuetypes": [
{
"self": "https://jira.atlassian.com/rest/api/2/issuetype/10000",
"id": "10000",
"description": "",
"iconUrl": "https://jira.atlassian.com/secure/viewavatar?size=xsmall&avatarId=51505&avatarType=issuetype",
"name": "Suggestion",
"subtask": false,
"expand": "fields",
"fields": {
"summary": {
"required": true,
"schema": {
"type": "string",
"system": "summary"
},
"name": "Summary",
"hasDefaultValue": false,
"operations": [
"set"
]
},
// other fields removed for brevity...
"components": {
"required": false,
"schema": {
"type": "array",
"items": "component",
"system": "components"
},
"name": "Component/s",
"hasDefaultValue": false,
"operations": [
"add",
"set",
"remove"
],
"allowedValues": [
{
"self": "https://jira.atlassian.com/rest/api/2/component/36920",
"id": "36920",
"name": "System Administration - Support Tools"
},
{
"self": "https://jira.atlassian.com/rest/api/2/component/43995",
"id": "43995",
"name": "User Management - Delete User"
}
]
}
// other fields removed for brevity...
}
}
]
}
]
}
The editmeta object allows you to search for the Single Select custom field and find its operations and values – only set and red, blue, green.
For example, to set the Single Select field to green during an edit, you can use the following JSON:
{
"update": {
"Single Select": [
{
"set": {"value": "green"}
}
]
}
}
特定のカスタム フィールドのカスタム フィールド ID を確認するためにメタ情報を使用することもできます。
フィールドを編集できない理由
If you've retrieved the createmeta or editmeta for your project or issue, the field you're trying to edit may not show up in the resulting JSON. This means when a rule attempts to edit or create the issue, it will fail with an error in the audit log.
This will most likely be due to the field missing on the appropriate edit or create screen in your project. To address this, go to Jira settings > Issues > Screens and ensure the field you’re trying to update is on the appropriate edit or create screen.
また、自動化ルールの実行担当者に、プロジェクトの課題の編集または作成を行うための適切な権限があるかどうかも確認します。
スマート バリューの使用
Due to recent GDPR changes, referencing user fields (such as reporter, assignee) now require the property id to be set with a user's account ID rather than using name.
Advanced field values also support smart values. Learn more about the JSON functions available as smart values.
たとえば、現在の担当者をイベントを開始したユーザーに変更するには以下のようになります。
{
"fields": {
"assignee": { "id": "{{initiator.accountId}}" }
}
}
他のフィールドの参照を簡単にするには、上記を次のように記述できます。
{
"fields": {
"assignee": {{initiator.accountId.asJsonObject("id")}}
}
}
これによって、JSON が正しいフォーマットで作成されるだけでなく、テキストも正しくエンコードされます。テキストを自動でエンコードするには、次のようにします。
{
"fields": {
"assignee": { "id": {{initiator.accountId.asJsonString}} }
}
}
値をキー付きの JSON オブジェクトに変換するには、次のようにします。
{
"fields": {
"assignee": {{initiator.name.asJsonObject("key")}}
}
}
結果は次のようになります。
{
"fields": {
"assignee": { "key": "username" }
}
}
テキストの配列を受け入れるフィールドの場合:
{
"fields": {
"labels": {{issue.parent.labels.asJsonStringArray}}
}
}
1 つのフィールド オブジェクトの配列を受け入れるフィールドの場合:
{
"fields": {
"Multi User Customfield": {{issue.parent.Multi User Customfield.accountId.asJsonObjectArray("id")}}
}
}
フィールドの構文の例
For more examples, view the Jira Cloud platform REST API documentation.
要約
1 行のテキストからなるシステム フィールド。
"summary": "A summary is one line of text"
説明
複数の行のテキストからなるシステム フィールド。
"description": "A description is many lines of text\n separated by\n line feeds"
時間トラッキングと作業の記録
タイム トラッキング機能を使用している場合、自動化を使用して関連フィールドを更新できます。タイム トラッキングは複数の値を表示するため originalEstimate
と remainingEstimate
は親フィールドの一部になります。
課題に対する作業を記録できます。
{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "6m"
}
}
]
}
}
または、作業を記録すると同時に残余見積もりを設定する場合は、以下の手順で行います。
{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "6m"
}
}
]
},
"fields": {
"timetracking": {
"originalEstimate": "10",
"remainingEstimate": "5"
}
}
}
You can combine this with smart values to log work using a calculated value:
{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "{{now.diff(issue.created).businessDays}}d"
}
}
]
}
}
別の課題から時間トラッキングのフィールドをコピーするには、次のようにします。
{
"fields": {
"timetracking": {
"originalEstimate": "{{issue.timetracking.originalEstimate}}",
"remainingEstimate": "{{issue.timetracking.remainingEstimate}}"
}
}
}
コンポーネント
A system field that is multiple values addressed by name.
"components" : [ { "name": "Active Directory"} , { "name": "Network Switch" } ]
影響バージョン
A system field that is multiple values addressed by name.
"versions" : [ { "name": "Version 1.0"} , { "Version": "1.1" } ]
修正バージョン
A system field that is multiple values addressed by name.
"fixVersions" : [ { "name": "2.0"} , { "name": "Network Switch" } ]
期限
「YYYY-MM-DD」フォーマットの日付のシステムフィールド。
"duedate" : "2015-11-18"
ラベル
テキスト値の配列のシステム フィールド。
"labels" : ["examplelabelnumber1", "examplelabelnumber2"]
ラベルを追加する
既存のラベル セットにラベルを追加します。
{
"update": {
"labels": [
{
"add": "my-new-label"
}
]
}
}
複数のラベルを既存のラベル セットに追加します。
{
"update": {
"labels": [
{
"add": "Label1"
},
{
"add": "Label2"
}
]
}
}
また、「add」の代わりに「remove」または「set」を演算子として使用できます。
課題のセキュリティ レベルを設定する
{
"update": {
"security": [
{
"set": {"name": "Public"}
}
]
}
}
In this case, Public is the name of the security level. Substitute this with a valid security level in your project.
課題をリンクする
課題リンクも作成できます。たとえば、既存の課題を編集して新規の課題を作成し、次に、編集した課題に戻るリンクを作成します。
{"update": {
"issuelinks": [
{
"add": {
"type": {
"name": "Relates"
},
"outwardIssue": {
"key": "{{issue.key}}"
}
}
}
]
}
}
To lookup the link type name (Relates in the above example), you can consult <yoursite>/secure/admin/ViewLinkTypes!default.jspa on your site. The {{issue.key}}
smart value replaces the key of the trigger issue.
リクエスト参加者
Jira Service Management の [リクエスト参加者] フィールドは、特定の構造になっている必要があります。たとえば、課題の最後のコメント者を参加者に加えるには、以下のように設定します。
{
"update": {
"Request participants" : [
{
"add": {
"id":"{{issue.comments.last.author.accountId}}"
}
}
]
}
}
チェックボックス型カスタム フィールド
Select multiple values from a defined list of values. You can address them by value or id.
"customfield_11440" : [{ "value" : "option1"}, {"value" : "option2"}]
or
"customfield_11440" : [{ "id" : 10112}, {"id" : 10115}]
日付ピッカー カスタム フィールド
"YYYY-MM-DD" 形式の日付。
"customfield_11441" : "2015-11-18"
日時ピッカー カスタム フィールド
ISO 8601 "YYYY-MM-DDThh:mm:ss.sTZD" 形式の日時。
"customfield_11442" : "2015-11-18T14:39:00.000+1100"
ラベル カスタム フィールド
テキストの配列です。
"customfield_11443" : [ "rest_label1", "rest_label2" ]
数値型カスタム フィールド
数字を含みます。
"customfield_11444" : 664
ラジオ ボタン型カスタム フィールド
Select a single value from a defined list of values. You can address them by value or id.
"customfield_11445" : { "value": "option2" }
or
"customfield_11445" : { "id": 10112 }
カスケード選択カスタム フィールド
Select a single parent value, and a related child value. You can address them by value or id.
"customfield_11447" : { "value": "parent_option1", "child": { "value" : "p1_child1"} }
or
"customfield_11447" : { "id": 10112, "child": { "id" : 10115 } }
複数選択カスタム フィールド
Select multiple values from a defined list of values. You can address them by value or id.
"customfield_11448" : [ { "value": "option1" }, { "value": "option2" } ]
or
"customfield_11448" : [ { "id": 10112 }, { "id": 10115 } ]
複数選択カスタム フィールドに値を追加します。たとえば、複数選択カスタム フィールドを持っていて、このフィールドに別のカスタム フィールドの値を追加したい場合などです。
{
"update": {
"customfield_12345": [{
"add": { "value": "{{issue.customfield_12224}}" }
}]
}
}
単一選択カスタム フィールド
Select a single value from a defined list of values. You can address them by value or id.
"customfield_11449" : { "value": "option3" }
or
"customfield_11449" : { "id": 10112 }
複数行テキスト カスタム フィールド
複数行のテキスト。
"customfield_11450": "Multiples lines of text\n separated by\n line feeds"
テキスト カスタム フィールド
1 行のテキスト。
"customfield_11450": "a single line of text"
URL カスタム フィールド
URL を取得します。
"customfield_11452" : "http://www.atlassian.com"
シングルユーザー ピッカー カスタム フィールド
1 人のユーザーを選択できます。
"customfield_11453" : { "id":"2s1863211f0z284c45269423" }
マルチユーザー ピッカー カスタム フィールド
複数のユーザーを選択できます。
"customfield_11458" : [ { "id":"2s1863211f0z284c45269423" }, { "id":"332212e13z52142111269423" }]
複数ユーザーピッカー カスタム フィールドに値を追加します。たとえば、課題の報告者を複数ユーザーピッカー カスタム フィールドに追加したい場合などです。その場合は、「その他のオプション」の下に次を追加する必要があります。
{
"update": {
"customfield_12346": [{
"add": {"id":"{{reporter.accountId}}"}
}]
}
}
Elements Connect (旧 nFeed) カスタム フィールド
文字列識別子の配列。
"customfield_10700" : [ "10300", "10400" ]
For example, copying the value of an Elements Connect field:
"customfield_10700" : {{ issue.customfield_10700.asJsonStringArray }}
この内容はお役に立ちましたか?