JSON を使用した詳細なフィールド編集
[その他のオプション] 追加フィールドは、フィールドが [Choose fields to set (フィールドを選択して設定)] を使用して編集できない場合のみ使用してください。これは他のアプリケーションによって提供されるカスタム フィールドで必要になる場合があります。
次の自動化アクションでは、フィールドを詳細に編集するためのフィールドが追加されます。
これらのフィールドにアクセスするには、アクションの設定時に [その他のオプション] を選択します。これらの追加フィールドには、Jira REST API が指定する形式を使用して、有効な JSON オブジェクトを指定する必要があります。
JSON のフォーマット
JSON オブジェクトには、属性 update または fields, などを含めることができます。
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"update": {
"description": {
"set": "a new description"
},
"labels": [{
"add": "test-label"
}]
},
"fields": {
"summary": "woohoo! a new summary"
}
}
update と fields の違い
fields はショートカットで、update を set 操作によって呼び出します。上記の例では、説明フィールドとして set を呼び出すことは description を fields セクションに含めることと等しくなります (例: {"fields": {"description":"a new description"}})。
update は、複数の値を持つフィールドの既存のセットに値を追加する、および/または既存のセットから値を削除する場合に役に立ちます。たとえば set 演算子を使用して課題にラベルを追加すると、既存ラベルはすべて上書きされますが update を使用すると、既存ラベルは削除せずにラベルが追加されます。
JSON の update セクションと fields の両方に同じフィールドが同時に表示されることはありません。
What issues may occur when editing fields?
Invalid JSON
This warning may occur if the JSON you entered was invalid. Check the syntax of your JSON and try again.
Valid JSON but smart value can’t be validated
In this case, the JSON is valid, but the smart values you entered into the field can’t be validated. This is because smart values can only be validated once a rule is executed. Check the audit log once your rule runs to ensure the smart values have worked as you planned.
JSON entered via smart value which can’t be validated
This warning may occur if you’ve attempted to enter all of your JSON through a smart value, however we can’t validate smart values until a rule is executed. Check the audit log once your rule runs to ensure the smart values have worked as you planned.
Valid JSON with missing keys
In this case, the JSON is valid, but we are unable to parse the additional fields as the update or fields keys are missing. Add at least one of these keys to your entry and try again.
課題フィールドを参照する
カスタム フィールドは ID でなく名前で参照できます。以下の例では、同じフィールドが ID と名前で参照されています。
1
2
3
4
5
6
{
"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 を使用する必要があります。
サポートされているフィールドとオペレーション
課題を作成または編集している場合、プロジェクトの createmeta 情報、または課題の editmeta 情報を検索して、サポートされているフィールドと演算子を表示できます。
この 2 つのオペレーションのメタデータは、以下より取得できます。
GET /rest/api/3/issue/createmeta?projectKeys=<string>&expand=projects.issuetypes.fields
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
この JSON は、可能なオペレーションおよび値を含め、Additional fields で使用できるすべてのフィールドを返します。
createmeta の応答としては以下が考えられます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
"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...
}
}
]
}
]
}
editmeta オブジェクトを使用すると、単一選択カスタム フィールドを検索し、演算子と値を検索できます (set と red、blue、green のみ)。
たとえば、編集中に [シングル セレクト] フィールドを緑色に設定するには、次の JSON を使用できます。
1
2
3
4
5
6
7
8
9
{
"update": {
"Single Select": [
{
"set": {"value": "green"}
}
]
}
}
特定のカスタム フィールドのカスタム フィールド ID を確認するためにメタ情報を使用することもできます。
フィールドを編集できない理由
プロジェクトまたは課題に対して createmeta または editmeta を取得した場合、編集対象のフィールドが結果として返される JSON に含まれていない場合があります。つまり、ルールが課題を編集または作成しようとすると、監査ログのエラーとなり実行できません。
多くの場合、プロジェクトの適切な編集または作成画面に該当するフィールドがないことが原因です。この問題を解決するには、[Jira 設定] > [課題] > [画面] の順に移動し、適切な編集画面または作成画面に更新するフィールドがあることを確認します。
また、自動化ルールの実行担当者に、プロジェクトの課題の編集または作成を行うための適切な権限があるかどうかも確認します。
スマート バリューの使用
GDPR の最近の変更によって、ユーザー フィールド (報告者、担当者など) を参照するには、プロパティ ID を名前ではなくユーザーのアカウント ID で設定する必要があります。
詳細なフィールド値でもスマート バリューがサポートされています。スマート バリューとして利用可能な JSON 関数の詳細をご確認ください。
たとえば、現在の担当者をイベントを開始したユーザーに変更するには以下のようになります。
1
2
3
4
5
{
"fields": {
"assignee": { "id": "{{initiator.accountId}}" }
}
}
他のフィールドの参照を簡単にするには、上記を次のように記述できます。
1
2
3
4
5
{
"fields": {
"assignee": {{initiator.accountId.asJsonObject("id")}}
}
}
これによって、JSON が正しいフォーマットで作成されるだけでなく、テキストも正しくエンコードされます。テキストを自動でエンコードするには、次のようにします。
1
2
3
4
5
{
"fields": {
"assignee": { "id": {{initiator.accountId.asJsonString}} }
}
}
値をキー付きの JSON オブジェクトに変換するには、次のようにします。
1
2
3
4
5
{
"fields": {
"assignee": {{initiator.name.asJsonObject("key")}}
}
}
結果は次のようになります。
1
2
3
4
5
{
"fields": {
"assignee": { "key": "username" }
}
}
テキストの配列を受け入れるフィールドの場合:
1
2
3
4
5
{
"fields": {
"labels": {{issue.parent.labels.asJsonStringArray}}
}
}
1 つのフィールド オブジェクトの配列を受け入れるフィールドの場合:
1
2
3
4
5
{
"fields": {
"Multi User Customfield": {{issue.parent.Multi User Customfield.accountId.asJsonObjectArray("id")}}
}
}
フィールドの構文の例
その他の例を見るには、「Jira Cloud プラットフォーム REST API のドキュメンテーション」を参照してください。
要約
1 行のテキストからなるシステム フィールド。
1
"summary": "A summary is one line of text"
説明
複数の行のテキストからなるシステム フィールド。
1
"description": "A description is many lines of text\n separated by\n line feeds"
時間トラッキングと作業の記録
タイム トラッキング機能を使用している場合、自動化を使用して関連フィールドを更新できます。タイム トラッキングは複数の値を表示するため originalEstimate と remainingEstimate は親フィールドの一部になります。
課題に対する作業を記録できます。
1
2
3
4
5
6
7
8
9
10
11
12
{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "6m"
}
}
]
}
}
または、作業を記録すると同時に残余見積もりを設定する場合は、以下の手順で行います。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "6m"
}
}
]
},
"fields": {
"timetracking": {
"originalEstimate": "10",
"remainingEstimate": "5"
}
}
}
これをスマート バリューと組み合わせると、計算した値を使用して作業を記録できます。
1
2
3
4
5
6
7
8
9
10
11
{
"update": {
"worklog" : [
{
"add": {
"timeSpent" : "{{now.diff(issue.created).businessDays}}d"
}
}
]
}
}
別の課題から時間トラッキングのフィールドをコピーするには、次のようにします。
1
2
3
4
5
6
7
8
{
"fields": {
"timetracking": {
"originalEstimate": "{{issue.timetracking.originalEstimate}}",
"remainingEstimate": "{{issue.timetracking.remainingEstimate}}"
}
}
}
コンポーネント
name で処理される、複数の値からなるシステム フィールド。
1
"components" : [ { "name": "Active Directory"} , { "name": "Network Switch" } ]
影響バージョン
name で処理される、複数の値からなるシステム フィールド。
1
"versions" : [ { "name": "Version 1.0"} , { "Version": "1.1" } ]
修正バージョン
name で処理される、複数の値からなるシステム フィールド。
1
"fixVersions" : [ { "name": "2.0"} , { "name": "Network Switch" } ]
期限
「YYYY-MM-DD」フォーマットの日付のシステムフィールド。
1
"duedate" : "2015-11-18"
ラベル
テキスト値の配列のシステム フィールド。
1
"labels" : ["examplelabelnumber1", "examplelabelnumber2"]
ラベルを追加する
既存のラベル セットにラベルを追加します。
1
2
3
4
5
6
7
8
9
{
"update": {
"labels": [
{
"add": "my-new-label"
}
]
}
}
複数のラベルを既存のラベル セットに追加します。
1
2
3
4
5
6
7
8
9
10
11
12
{
"update": {
"labels": [
{
"add": "Label1"
},
{
"add": "Label2"
}
]
}
}
また、「add」の代わりに「remove」または「set」を演算子として使用できます。
課題のセキュリティ レベルを設定する
1
2
3
4
5
6
7
8
9
{
"update": {
"security": [
{
"set": {"name": "Public"}
}
]
}
}
このケースでは、Public がセキュリティ レベルの名前になります。この名前の代わりにプロジェクトの有効なセキュリティ レベルを使用できます。
課題をリンクする
課題リンクも作成できます。たとえば、既存の課題を編集して新規の課題を作成し、次に、編集した課題に戻るリンクを作成します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{"update": {
"issuelinks": [
{
"add": {
"type": {
"name": "Relates"
},
"outwardIssue": {
"key": "{{issue.key}}"
}
}
}
]
}
}
リンクのタイプ名 (上記の例の Relates) を検索するには、サイトの "<yoursite>/secure/admin/ViewLinkTypes!default.jspa" を参照してください。スマート バリュー {{issue.key}} はトリガー課題のキーと置き換えられます。
リクエスト参加者
Jira Service Management の [リクエスト参加者] フィールドは、特定の構造になっている必要があります。たとえば、課題の最後のコメント者を参加者に加えるには、以下のように設定します。
1
2
3
4
5
6
7
8
9
10
11
{
"update": {
"Request participants" : [
{
"add": {
"id":"{{issue.comments.last.author.accountId}}"
}
}
]
}
}
チェックボックス型カスタム フィールド
値の定義リストから複数の値を選択します。value または id で指定できます。
1
2
3
4
5
"customfield_11440" : [{ "value" : "option1"}, {"value" : "option2"}]
or
"customfield_11440" : [{ "id" : 10112}, {"id" : 10115}]
日付ピッカー カスタム フィールド
"YYYY-MM-DD" 形式の日付。
1
"customfield_11441" : "2015-11-18"
日時ピッカー カスタム フィールド
ISO 8601 "YYYY-MM-DDThh:mm:ss.sTZD" 形式の日時。
1
"customfield_11442" : "2015-11-18T14:39:00.000+1100"
ラベル カスタム フィールド
テキストの配列です。
1
"customfield_11443" : [ "rest_label1", "rest_label2" ]
数値型カスタム フィールド
数字を含みます。
1
"customfield_11444" : 664
ラジオ ボタン型カスタム フィールド
値の定義リストから、単一の値を選択します。value または id で指定できます。
1
2
3
4
5
"customfield_11445" : { "value": "option2" }
or
"customfield_11445" : { "id": 10112 }
カスケード選択カスタム フィールド
1 つの親の値とそれに関連する子の値を選択します。value または id で指定できます。
1
2
3
4
5
"customfield_11447" : { "value": "parent_option1", "child": { "value" : "p1_child1"} }
or
"customfield_11447" : { "id": 10112, "child": { "id" : 10115 } }
複数選択カスタム フィールド
値の定義リストから複数の値を選択します。value または id で指定できます。
1
2
3
4
5
"customfield_11448" : [ { "value": "option1" }, { "value": "option2" } ]
or
"customfield_11448" : [ { "id": 10112 }, { "id": 10115 } ]
複数選択カスタム フィールドに値を追加します。たとえば、複数選択カスタム フィールドを持っていて、このフィールドに別のカスタム フィールドの値を追加したい場合などです。
1
2
3
4
5
6
7
{
"update": {
"customfield_12345": [{
"add": { "value": "{{issue.customfield_12224}}" }
}]
}
}
単一選択カスタム フィールド
値の定義リストから、単一の値を選択します。value または id で指定できます。
1
2
3
4
5
"customfield_11449" : { "value": "option3" }
or
"customfield_11449" : { "id": 10112 }
複数行テキスト カスタム フィールド
複数行のテキスト。
1
"customfield_11450": "Multiples lines of text\n separated by\n line feeds"
テキスト カスタム フィールド
1 行のテキスト。
1
"customfield_11450": "a single line of text"
URL カスタム フィールド
URL を取得します。
1
"customfield_11452" : "http://www.atlassian.com"
シングルユーザー ピッカー カスタム フィールド
1 人のユーザーを選択できます。
1
"customfield_11453" : { "id":"2s1863211f0z284c45269423" }
マルチユーザー ピッカー カスタム フィールド
複数のユーザーを選択できます。
1
"customfield_11458" : [ { "id":"2s1863211f0z284c45269423" }, { "id":"332212e13z52142111269423" }]
複数ユーザーピッカー カスタム フィールドに値を追加します。たとえば、課題の報告者を複数ユーザーピッカー カスタム フィールドに追加したい場合などです。その場合は、「その他のオプション」の下に次を追加する必要があります。
1
2
3
4
5
6
7
{
"update": {
"customfield_12346": [{
"add": {"id":"{{reporter.accountId}}"}
}]
}
}
Elements Connect (旧 nFeed) カスタム フィールド
文字列識別子の配列。
1
"customfield_10700" : [ "10300", "10400" ]
たとえば、Elements Connect フィールドの値をコピーするには、以下の手順で行います。
1
"customfield_10700" : {{ issue.customfield_10700.asJsonStringArray }}
この内容はお役に立ちましたか?