Платформа 3V/Отчет/2. Настроить столбцы/2.5. Дополнительные настройки/Установка значения по умолчанию

Материал из 3v-wiki
Перейти к навигации Перейти к поиску

При необходимости указать значение по умолчанию для какого-либо столбца отчета существует две различные ситуации, от которых зависит способ настройки данного значения. Установка значения по умолчанию:

  1. В атрибут справочника
  2. В факт показателя

Установка значения по умолчанию в атрибут справочника

Для установки значения по умолчанию в столбец отчета, который является атрибутом справочника, необходимо в самом справочнике в требуемом атрибуте указать свойство defaultValue или defaultValueExpression при постоянном значении по умолчанию или вычисляемом определенным выражением соответственно

"attributes": [...]
 1 "view": 
 2     {
 3      "id": 21,
 4      "name": "...",
 5      "code": "...",
 6      ...
 7      "defaultValue": "...",
 8      "defaultValueExpression": "..."
 9      ...
10     }

Кейс: Необходимо отображать информацию о существующих в системе заявках, а так же создавать новые заявки через отчет с заполненными по умолчанию атрибутами. Для этого создан справочник "Заявки на работу" и необходимо в атрибут "Номер заявки" указать значение по умолчанию "Новая заявка", а атрибут "Дата создания" вычислить и заполнить текущей датой и атрибут "Актуальность" по умолчанию заполнить True

Номер заявки (id=2) Дата создания (id=21) Актуальность (id=22)
102-1-1 02.02.2021 True
102-1-2 09.04.2021 False
... ... ...
Установка значения по умолчанию. атрибут справочник.gif
Настройки атрибутов в справочнике. "attributes": [...]
 1       {
 2         "id": 2,
 3         "name": "Номер заявки",
 4         "code": "NAME",
 5         "description": "",
 6         "dataType": "String",
 7         "type": "Name",
 8         "isNullable": false,
 9         "hasMultipleValues": false,
10         "isVisible": true,
11         "isReadOnly": false,
12         "formula": null,
13         "tableName": "",
14         "identIndex": {
15           "code": null,
16           "isUnique": false,
17           "dbIndexName": null,
18           "fields": [],
19           "isNew": true
20         },
21         "referenceIndex": {
22           "code": null,
23           "isUnique": false,
24           "dbIndexName": null,
25           "fields": [],
26           "isNew": true
27         },
28         "attributeLink": null,
29         "defaultValue": "Новая заявка",
30         "defaultValueExpression": null,
31         "userAttributePermissions": null,
32         "component": null
33       },
34       {
35         "id": 21,
36         "name": "Дата создания",
37         "code": "DATE_CREATE",
38         "description": "",
39         "dataType": "DateTime",
40         "type": "Custom",
41         "isNullable": true,
42         "hasMultipleValues": false,
43         "isVisible": true,
44         "isReadOnly": false,
45         "formula": null,
46         "tableName": "",
47         "identIndex": {
48           "code": null,
49           "isUnique": false,
50           "dbIndexName": null,
51           "fields": [],
52           "isNew": true
53         },
54         "referenceIndex": {
55           "code": null,
56           "isUnique": false,
57           "dbIndexName": null,
58           "fields": [],
59           "isNew": true
60         },
61         "attributeLink": null,
62         "defaultValue": null,
63         "defaultValueExpression": "Today()",
64         "userAttributePermissions": null,
65         "component": null
66       },
67       {
68         "id": 22,
69         "name": "Актуальность",
70         "code": "ACTUAL",
71         "description": "",
72         "dataType": "Boolean",
73         "type": "Custom",
74         "isNullable": true,
75         "hasMultipleValues": false,
76         "isVisible": true,
77         "isReadOnly": false,
78         "formula": null,
79         "tableName": "",
80         "identIndex": {
81           "code": null,
82           "isUnique": false,
83           "dbIndexName": null,
84           "fields": [],
85           "isNew": true
86         },
87         "referenceIndex": {
88           "code": null,
89           "isUnique": false,
90           "dbIndexName": null,
91           "fields": [],
92           "isNew": true
93         },
94         "attributeLink": null,
95         "defaultValue": "true",
96         "defaultValueExpression": null,
97         "userAttributePermissions": null,
98         "component": null
99       }

При этом в самом отчете никакой дополнительной настройки не требуется:

JSON отчета
  1       {
  2   "workflowId": null,
  3   "leftHeader": {
  4     "useLazyDataLoadingStrategy": false,
  5     "dictionaries": [
  6       {
  7         "showDataIfAbsentFilter": null,
  8         "coordAttribute": null,
  9         "cartesianOptions": "Default",
 10         "canSelectAttribute": null,
 11         "groupingOptions": null,
 12         "groupingMethod": "Default",
 13         "sortingOptions": null,
 14         "rootElement": null,
 15         "virtualElements": null,
 16         "displayValueOptions": null,
 17         "displayAttribute": null,
 18         "dictionaryId": 185,
 19         "filter": {
 20           "value": null,
 21           "skipIfValueNull": false,
 22           "attributeId": null,
 23           "attribute": {
 24             "id": 1,
 25             "discriminator": "OwnAttributeDefinitionDto"
 26           },
 27           "conditionType": "AllElements",
 28           "inversion": false,
 29           "discriminator": "ValueConditionalDictionaryFilterDto"
 30         },
 31         "selection": null,
 32         "hierarchyId": null,
 33         "limit": null
 34       }
 35     ],
 36     "dictionaryAttributesLinks": [],
 37     "specialFilters": {
 38       "filtersByDataOptions": {
 39         "filtersByData": [],
 40         "needRestoreFullHierachy": false,
 41         "joinOption": "Or",
 42         "restoreElements": null
 43       },
 44       "dictionaryAttributesLinks": [],
 45       "needRestoreFullHierachy": false,
 46       "restoreElements": null
 47     },
 48     "isEditable": false
 49   },
 50   "topHeader": {
 51     "topHeaderItems": [
 52       {
 53         "dictionaryAttributes": [
 54           {
 55             "dictionaryId": 185,
 56             "attribute": {
 57               "id": 2,
 58               "discriminator": "OwnAttributeDefinitionDto"
 59             },
 60             "filter": null,
 61             "sortingOptions": null,
 62             "attributeId": null,
 63             "displayAttributeType": "AttributeName",
 64             "displayAttributeName": null,
 65             "addFirstElementValue": false,
 66             "overwriteNotFirstElementValues": true,
 67             "delimiter": ", ",
 68             "hideAttributeNameInHeader": false,
 69             "headerNameDelimiter": " / ",
 70             "duplicateValuesForNextDictionaries": true,
 71             "duplicateValuesForNextRows": true,
 72             "displayValueOptions": null,
 73             "linkedAttributeSettings": null,
 74             "skippedFilterAttributesByLink": [],
 75             "filterOptionsByLinks": null
 76           }
 77         ],
 78         "settings": null,
 79         "hyperlinkOptions": null,
 80         "hasImage": false,
 81         "columnOptions": null,
 82         "discriminator": "AttributeHeaderItemDto"
 83       },
 84       {
 85         "dictionaryAttributes": [
 86           {
 87             "dictionaryId": 185,
 88             "attribute": {
 89               "id": 21,
 90               "discriminator": "OwnAttributeDefinitionDto"
 91             },
 92             "filter": null,
 93             "sortingOptions": null,
 94             "attributeId": null,
 95             "displayAttributeType": "AttributeName",
 96             "displayAttributeName": null,
 97             "addFirstElementValue": false,
 98             "overwriteNotFirstElementValues": true,
 99             "delimiter": ", ",
100             "hideAttributeNameInHeader": false,
101             "headerNameDelimiter": " / ",
102             "duplicateValuesForNextDictionaries": true,
103             "duplicateValuesForNextRows": true,
104             "displayValueOptions": null,
105             "linkedAttributeSettings": null,
106             "skippedFilterAttributesByLink": [],
107             "filterOptionsByLinks": null
108           }
109         ],
110         "settings": null,
111         "hyperlinkOptions": null,
112         "hasImage": false,
113         "columnOptions": null,
114         "discriminator": "AttributeHeaderItemDto"
115       },
116       {
117         "dictionaryAttributes": [
118           {
119             "dictionaryId": 185,
120             "attribute": {
121               "id": 22,
122               "discriminator": "OwnAttributeDefinitionDto"
123             },
124             "filter": null,
125             "sortingOptions": null,
126             "attributeId": null,
127             "displayAttributeType": "AttributeName",
128             "displayAttributeName": null,
129             "addFirstElementValue": false,
130             "overwriteNotFirstElementValues": true,
131             "delimiter": ", ",
132             "hideAttributeNameInHeader": false,
133             "headerNameDelimiter": " / ",
134             "duplicateValuesForNextDictionaries": true,
135             "duplicateValuesForNextRows": true,
136             "displayValueOptions": null,
137             "linkedAttributeSettings": null,
138             "skippedFilterAttributesByLink": [],
139             "filterOptionsByLinks": null
140           }
141         ],
142         "settings": null,
143         "hyperlinkOptions": null,
144         "hasImage": false,
145         "columnOptions": {
146           "width": 150,
147           "format": null,
148           "dataControlOptions": {
149             "format": null,
150             "mask": null,
151             "min": null,
152             "max": null,
153             "component": null,
154             "searchSettings": null
155           },
156           "isReadOnly": null,
157           "displayDuplicatedValues": null,
158           "duplicateValueOptions": "Undefined",
159           "allowChangeColumnValue": null,
160           "singleValueColumn": null,
161           "hyperlinkOptions": null,
162           "imageType": "None",
163           "absentDictionariesOptions": null
164         },
165         "discriminator": "AttributeHeaderItemDto"
166       }
167     ],
168     "needFilterAttributesByLinks": false,
169     "enableFilterByLinks": false,
170     "numerationSettings": null,
171     "filterOptions": null
172   },
173   "parameters": [],
174   "styles": [],
175   "styleOptions": [],
176   "stylesTemplate": [],
177   "filtersByDataOptions": null,
178   "view": null,
179   "externalExecutions": null,
180   "settings": null,
181   "code": "P_DEFAULT_DICT",
182   "id": 186,
183   "name": "Значение по умолчанию в атрибуте справочника"
184 }

Установка значения по умолчанию в факт показателя

Для установки значения по умолчанию в столбец кубовой формы, который является фактом показателя, необходимо в самом показателе в в блоке factOptions указать свойство defaultValue определенного факта

"factOptions": [...]
1 "view": 
2      {
3       "factElementId": ...,
4       "defaultValue": "..."
5     }

Кейс: Информация о наличии различных продуктов в определенных магазинах хранится показателе "Наличие продуктов", у которого в качестве измерений справочники "Магазины" и "Продукты" и логический факт "Наличие продуктов" и необходимо в данный факт указать значение по умолчанию "true" при добавлении строки в отчет.

Установка значения по умолчанию в факт показателя.gif
Настройка показателя
 1       {
 2   "virtualTable": {
 3     "name": "ind_189",
 4     "columns": [
 5       {
 6         "name": "fact",
 7         "defaultValueExpression": null,
 8         "id": 0,
 9         "dataType": "Boolean",
10         "isArray": false,
11         "discriminator": "DbColumnDto"
12       },
13       {
14         "name": "d_191_id",
15         "defaultValueExpression": "1",
16         "id": 1,
17         "dataType": "Integer",
18         "isArray": false,
19         "discriminator": "DbColumnDto"
20       },
21       {
22         "name": "d_190_id",
23         "defaultValueExpression": "1",
24         "id": 2,
25         "dataType": "Integer",
26         "isArray": false,
27         "discriminator": "DbColumnDto"
28       }
29     ],
30     "id": 0,
31     "connectionId": 0,
32     "discriminator": "DbTableDto"
33   },
34   "factColumnId": 0,
35   "isHistoryEnabled": false,
36   "isReadonly": false,
37   "isCached": false,
38   "isDataSourceExternal": false,
39   "indicatorDictionaries": [
40     {
41       "mappings": [
42         {
43           "attributeId": 1,
44           "columnId": 1
45         }
46       ],
47       "dictionaryId": 191,
48       "discriminator": "DataIndicatorDictionaryDto"
49     },
50     {
51       "mappings": [
52         {
53           "attributeId": 1,
54           "columnId": 2
55         }
56       ],
57       "dictionaryId": 190,
58       "discriminator": "DataIndicatorDictionaryDto"
59     }
60   ],
61   "factOptions": [
62     {
63       "factElementId": -1,
64       "defaultValue": "true"
65     }
66   ],
67   "isAccessRightsEnabled": false,
68   "code": "New_Indicator_3",
69   "id": 189,
70   "name": "Наличие продуктов",
71   "discriminator": "DataIndicatorDto"
72 }

При этом в самом отчете никакой дополнительной настройки не требуется, кроме стандартных настроек для формирования кубовой формы:

JSON отчета
  1 {
  2   "workflowId": null,
  3   "leftHeader": {
  4     "useLazyDataLoadingStrategy": false,
  5     "dictionaries": [
  6       {
  7         "showDataIfAbsentFilter": null,
  8         "coordAttribute": null,
  9         "cartesianOptions": "Default",
 10         "canSelectAttribute": null,
 11         "groupingOptions": null,
 12         "groupingMethod": "Default",
 13         "sortingOptions": null,
 14         "rootElement": null,
 15         "virtualElements": null,
 16         "displayValueOptions": null,
 17         "displayAttribute": null,
 18         "dictionaryId": 191,
 19         "filter": {
 20           "value": null,
 21           "skipIfValueNull": false,
 22           "attributeId": null,
 23           "attribute": {
 24             "id": 1,
 25             "discriminator": "OwnAttributeDefinitionDto"
 26           },
 27           "conditionType": "AllElements",
 28           "inversion": false,
 29           "discriminator": "ValueConditionalDictionaryFilterDto"
 30         },
 31         "selection": null,
 32         "hierarchyId": null,
 33         "limit": null
 34       },
 35       {
 36         "showDataIfAbsentFilter": null,
 37         "coordAttribute": null,
 38         "cartesianOptions": "Default",
 39         "canSelectAttribute": null,
 40         "groupingOptions": null,
 41         "groupingMethod": "Default",
 42         "sortingOptions": null,
 43         "rootElement": null,
 44         "virtualElements": null,
 45         "displayValueOptions": null,
 46         "displayAttribute": null,
 47         "dictionaryId": 190,
 48         "filter": {
 49           "value": null,
 50           "skipIfValueNull": false,
 51           "attributeId": null,
 52           "attribute": {
 53             "id": 1,
 54             "discriminator": "OwnAttributeDefinitionDto"
 55           },
 56           "conditionType": "AllElements",
 57           "inversion": false,
 58           "discriminator": "ValueConditionalDictionaryFilterDto"
 59         },
 60         "selection": null,
 61         "hierarchyId": null,
 62         "limit": null
 63       }
 64     ],
 65     "dictionaryAttributesLinks": [],
 66     "specialFilters": {
 67       "filtersByDataOptions": {
 68         "filtersByData": [
 69           {
 70             "indicatorId": 189,
 71             "filterOptions": [],
 72             "takeHeadersSelectionIfAbsent": false,
 73             "dataCondition": null
 74           }
 75         ],
 76         "needRestoreFullHierachy": false,
 77         "joinOption": "Or",
 78         "restoreElements": null
 79       },
 80       "dictionaryAttributesLinks": [],
 81       "needRestoreFullHierachy": false,
 82       "restoreElements": null
 83     },
 84     "isEditable": true
 85   },
 86   "topHeader": {
 87     "topHeaderItems": [
 88       {
 89         "dictionaryAttributes": [
 90           {
 91             "dictionaryId": 191,
 92             "attribute": {
 93               "id": 2,
 94               "discriminator": "OwnAttributeDefinitionDto"
 95             },
 96             "filter": null,
 97             "sortingOptions": null,
 98             "attributeId": null,
 99             "displayAttributeType": "CustomAttributeName",
100             "displayAttributeName": "Магазин",
101             "addFirstElementValue": false,
102             "overwriteNotFirstElementValues": true,
103             "delimiter": ", ",
104             "hideAttributeNameInHeader": false,
105             "headerNameDelimiter": " / ",
106             "duplicateValuesForNextDictionaries": true,
107             "duplicateValuesForNextRows": true,
108             "displayValueOptions": null,
109             "linkedAttributeSettings": null,
110             "skippedFilterAttributesByLink": [],
111             "filterOptionsByLinks": null
112           }
113         ],
114         "settings": {
115           "showExpanders": false,
116           "showHierarchyIndent": false,
117           "allowsMultipleValues": null,
118           "aggregationType": "None",
119           "transformAggregationType": "None",
120           "linkedCanSelectAttribute": null
121         },
122         "hyperlinkOptions": null,
123         "hasImage": false,
124         "columnOptions": {
125           "width": null,
126           "format": null,
127           "dataControlOptions": {
128             "format": null,
129             "mask": null,
130             "min": null,
131             "max": null,
132             "component": null,
133             "searchSettings": null
134           },
135           "isReadOnly": null,
136           "displayDuplicatedValues": null,
137           "duplicateValueOptions": "Undefined",
138           "allowChangeColumnValue": null,
139           "singleValueColumn": null,
140           "hyperlinkOptions": null,
141           "imageType": "None",
142           "absentDictionariesOptions": null
143         },
144         "discriminator": "AttributeHeaderItemDto"
145       },
146       {
147         "dictionaryAttributes": [
148           {
149             "dictionaryId": 190,
150             "attribute": {
151               "id": 2,
152               "discriminator": "OwnAttributeDefinitionDto"
153             },
154             "filter": null,
155             "sortingOptions": null,
156             "attributeId": null,
157             "displayAttributeType": "CustomAttributeName",
158             "displayAttributeName": "Продукт",
159             "addFirstElementValue": false,
160             "overwriteNotFirstElementValues": true,
161             "delimiter": ", ",
162             "hideAttributeNameInHeader": false,
163             "headerNameDelimiter": " / ",
164             "duplicateValuesForNextDictionaries": true,
165             "duplicateValuesForNextRows": true,
166             "displayValueOptions": null,
167             "linkedAttributeSettings": null,
168             "skippedFilterAttributesByLink": [],
169             "filterOptionsByLinks": null
170           }
171         ],
172         "settings": null,
173         "hyperlinkOptions": null,
174         "hasImage": false,
175         "columnOptions": {
176           "width": null,
177           "format": null,
178           "dataControlOptions": {
179             "format": null,
180             "mask": null,
181             "min": null,
182             "max": null,
183             "component": null,
184             "searchSettings": null
185           },
186           "isReadOnly": null,
187           "displayDuplicatedValues": null,
188           "duplicateValueOptions": "Undefined",
189           "allowChangeColumnValue": null,
190           "singleValueColumn": null,
191           "hyperlinkOptions": null,
192           "imageType": "None",
193           "absentDictionariesOptions": null
194         },
195         "discriminator": "AttributeHeaderItemDto"
196       },
197       {
198         "indicatorId": 189,
199         "isVisible": true,
200         "dictionaries": [],
201         "formulas": [],
202         "aggregations": [
203           {
204             "type": "None",
205             "dictionaryFilterOptions": null
206           }
207         ],
208         "transformAggregationType": "None",
209         "hierarchyOptions": null,
210         "factOptions": null,
211         "columnOptions": {
212           "width": 100,
213           "format": null,
214           "dataControlOptions": {
215             "format": null,
216             "mask": null,
217             "min": null,
218             "max": null,
219             "component": null,
220             "searchSettings": null
221           },
222           "isReadOnly": null,
223           "displayDuplicatedValues": null,
224           "duplicateValueOptions": "Undefined",
225           "allowChangeColumnValue": null,
226           "singleValueColumn": null,
227           "hyperlinkOptions": null,
228           "imageType": "None",
229           "absentDictionariesOptions": null
230         },
231         "discriminator": "IndicatorOptionsDto"
232       }
233     ],
234     "needFilterAttributesByLinks": false,
235     "enableFilterByLinks": false,
236     "numerationSettings": null,
237     "filterOptions": null
238   },
239   "parameters": [],
240   "styles": [],
241   "styleOptions": [],
242   "stylesTemplate": [],
243   "filtersByDataOptions": null,
244   "view": null,
245   "externalExecutions": null,
246   "settings": null,
247   "code": "P_DEFAULT_IND",
248   "id": 192,
249   "name": "Значение по умолчанию в атрибуте справочника"
250 }