Skip to content

Commit 45786c4

Browse files
committed
update
1 parent 5f87b93 commit 45786c4

File tree

1 file changed

+117
-66
lines changed

1 file changed

+117
-66
lines changed

docs/learn/rossum-formulas/index.md

Lines changed: 117 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: 'Rossum Formulas'
33
sidebar_position: 1
44
---
55

6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
69
This section covers both the Rossum **Formula Fields** and the **Serverless Functions** (Formula Fields flavor in custom extensions).
710

811
## Installation
@@ -76,92 +79,112 @@ def rossum_hook_request_handler(payload):
7679

7780
Formula field examples do not require any further modification.
7881

79-
### Get datapoint value
82+
### Working with datapoints
8083

81-
#### Formula field
84+
<Tabs groupId="rossum-formulas-flavor">
85+
<TabItem value="formula_field" label="Formula field" default>
8286

83-
Can be either returned directly from the formula fields or stored in some temporary variable.
87+
Getting values (or meta information):
8488

8589
```py
86-
field.amount
90+
field.amount # Get datapoint value
91+
field.amount.id # Get datapoint system ID
92+
field.amount.attr.rir_confidence # Get confidence score
93+
field.amount.attr.ocr_raw_text # Get raw value extracted by OCR, if applicable
94+
field.amount.attr.rir_raw_text # Get raw extracted text by RIR
8795
```
8896

89-
#### Serverless function
97+
:::warning
9098

91-
In case of serverless function, the value can never be returned directly and must be either used in some other function call, or stored in some temporary variable to be used later:
99+
Formula fields cannot write into any other fields. They simply return the value into the formula field itself.
92100

93-
```py
94-
tmp = t.field.amount
95-
```
101+
:::
96102

97-
### Get datapoint metadata
103+
</TabItem>
104+
<TabItem value="serverless_function" label="Serverless function">
98105

99-
#### Formula field
106+
Getting values (or meta information):
100107

101108
```py
102-
field.amount.id # Datapoint system ID
103-
field.amount.attr.rir_confidence # Confidence score
104-
field.amount.attr.ocr_raw_text # Raw value extracted by OCR, if applicable
105-
field.amount.attr.rir_raw_text # Raw extracted text by RIR
109+
t.field.amount # Get datapoint value
110+
t.field.amount.id # Get datapoint system ID
111+
t.field.amount.rir_confidence # Get confidence score
112+
t.field.amount.attr.ocr_raw_text # Get raw value extracted by OCR, if applicable
113+
t.field.amount.attr.rir_raw_text # Get raw extracted text by RIR
106114
```
107115

108-
#### Serverless function
116+
Writing values:
109117

110118
```py
111-
t.field.amount.id
112-
t.field.amount.rir_confidence
113-
114-
t.field.amount.attr.ocr_raw_text
115-
t.field.amount.attr.rir_raw_text
119+
t.field.amount = 10
116120
```
117121

118-
### Write into datapoint value
122+
</TabItem>
123+
</Tabs>
119124

120-
#### Formula field
125+
### Working with annotation data
121126

122-
:::warning
127+
<Tabs groupId="rossum-formulas-flavor">
128+
<TabItem value="formula_field" label="Formula field" default>
123129

124-
Formula fields cannot write into any other fields. They simply return the value into the formula field itself.
125-
126-
:::
130+
```py
131+
annotation.id # Get annotation ID
132+
annotation.metadata # Get annotation metadata
133+
annotation.document.original_file_name # Get document original file name
134+
annotation.email.subject # Get email subject
135+
```
127136

128-
#### Serverless function
137+
</TabItem>
138+
<TabItem value="serverless_function" label="Serverless function">
129139

130140
```py
131-
t.field.amount = 10
141+
t.annotation.id # Get annotation ID
142+
t.annotation.metadata # Get annotation metadata
143+
t.annotation.document.original_file_name # Get document original file name
144+
t.annotation.email.subject # Get email subject
132145
```
133146

147+
</TabItem>
148+
</Tabs>
149+
134150
### Check whether datapoint is set or not
135151

136-
#### Formula field
152+
<Tabs groupId="rossum-formulas-flavor">
153+
<TabItem value="formula_field" label="Formula field" default>
137154

138155
```py
139-
is_set(field.amount) # Returns `true` if datapoint is set (has value)
140-
is_empty(field.amount) # Opposite of `is_set`
156+
is_set(field.amount) # Returns `true` if datapoint is set (has value)
157+
is_empty(field.amount) # Opposite of `is_set`
141158
```
142159

143-
#### Serverless function
160+
</TabItem>
161+
<TabItem value="serverless_function" label="Serverless function">
144162

145163
```py
146164
from txscript import TxScript, is_set, is_empty
147165

148166
#
149167

150-
is_set(t.field.amount)
151-
is_empty(t.field.amount)
168+
is_set(t.field.amount) # Returns `true` if datapoint is set (has value)
169+
is_empty(t.field.amount) # Opposite of `is_set`
152170
```
153171

172+
</TabItem>
173+
</Tabs>
174+
154175
### Defaulting values
155176

156177
Use the default value if the field is empty.
157178

158-
#### Formula field
179+
<Tabs groupId="rossum-formulas-flavor">
180+
<TabItem value="formula_field" label="Formula field" default>
159181

160182
```py
161183
default_to(field.amount, 0)
162184
```
163185

164-
#### Serverless function
186+
</TabItem>
187+
<TabItem value="serverless_function" label="Serverless function">
165188

166189
```py
167190
from txscript import TxScript, default_to
@@ -171,11 +194,15 @@ from txscript import TxScript, default_to
171194
default_to(t.field.amount, 0)
172195
```
173196

197+
</TabItem>
198+
</Tabs>
199+
174200
### Substitute
175201

176202
Substitute is an alias for [`re.sub`](https://docs.python.org/3/library/re.html#re.sub) function (for convenience).
177203

178-
#### Formula field
204+
<Tabs groupId="rossum-formulas-flavor">
205+
<TabItem value="formula_field" label="Formula field" default>
179206

180207
```py
181208
substitute(r"[^0-9]", r"", field.document_id) # Remove non-digit characters
@@ -187,7 +214,8 @@ Could also be written as (`re` is imported automatically):
187214
re.sub(r"[^0-9]", r"", field.document_id)
188215
```
189216

190-
#### Serverless function
217+
</TabItem>
218+
<TabItem value="serverless_function" label="Serverless function">
191219

192220
```py
193221
from txscript import TxScript, substitute
@@ -197,40 +225,48 @@ from txscript import TxScript, substitute
197225
substitute(r"[^0-9]", r"", t.field.document_id)
198226
```
199227

228+
</TabItem>
229+
</Tabs>
230+
200231
### Show info/warning/error messages
201232

202-
#### Formula field
233+
:::note
203234

204-
```py
205-
show_info("") # Show global info message
206-
show_info("", field.amount) # Show info message on the specified field
235+
Messages do not affect the automation behavior and, therefore, automation blockers must be set explicitly (see how to set [automation blockers](#set-automation-blockers)). The only exception is `show_error` which always blocks the automation.
207236

208-
show_warning("") # Show global warning message
209-
show_warning("", field.amount) # Show warning message on the specified field
237+
:::
210238

211-
show_error("") # Show global error message
212-
show_error("", field.amount) # Show error message on the specified field
213-
```
239+
<Tabs groupId="rossum-formulas-flavor">
240+
<TabItem value="formula_field" label="Formula field" default>
214241

215-
#### Serverless function
242+
```py
243+
show_info("") # Show global info message
244+
show_info("", field.amount) # Show info message on the specified field
216245

217-
:::note
246+
show_warning("") # Show global warning message
247+
show_warning("", field.amount) # Show warning message on the specified field
218248

219-
Messages do not affect the automation behavior and, therefore, automation blockers must be set explicitly (see how to set [automation blockers](#set-automation-blockers)). The only exception is `show_error` which always blocks the automation.
249+
show_error("") # Show global error message
250+
show_error("", field.amount) # Show error message on the specified field
251+
```
220252

221-
:::
253+
</TabItem>
254+
<TabItem value="serverless_function" label="Serverless function">
222255

223256
```py
224-
t.show_info("")
225-
t.show_info("", t.field.amount)
257+
t.show_info("") # Show global info message
258+
t.show_info("", t.field.amount) # Show info message on the specified field
226259

227-
t.show_warning("")
228-
t.show_warning("", t.field.amount)
260+
t.show_warning("") # Show global warning message
261+
t.show_warning("", t.field.amount) # Show warning message on the specified field
229262

230-
t.show_error("")
231-
t.show_error("", t.field.amount)
263+
t.show_error("") # Show global error message
264+
t.show_error("", t.field.amount) # Show error message on the specified field
232265
```
233266

267+
</TabItem>
268+
</Tabs>
269+
234270
### Set automation blockers
235271

236272
:::note
@@ -239,47 +275,62 @@ Automation blockers must be set independently of the info/warning messages. Erro
239275

240276
:::
241277

242-
#### Formula field
278+
<Tabs groupId="rossum-formulas-flavor">
279+
<TabItem value="formula_field" label="Formula field" default>
243280

244281
```py
245282
automation_blocker("message", field.amount)
246283
```
247284

248-
#### Serverless function
285+
</TabItem>
286+
<TabItem value="serverless_function" label="Serverless function">
249287

250288
```py
251289
t.automation_blocker("message", t.field.amount)
252290
```
253291

292+
</TabItem>
293+
</Tabs>
294+
254295
### Create multivalue field values
255296

256-
#### Formula field
297+
<Tabs groupId="rossum-formulas-flavor">
298+
<TabItem value="formula_field" label="Formula field" default>
257299

258300
:::warning
259301

260-
Multivalue formula fields are currently not supported.
302+
Multivalue formula fields are currently not supported (only serverless functions).
261303

262304
:::
263305

264-
#### Serverless function
306+
</TabItem>
307+
<TabItem value="serverless_function" label="Serverless function">
265308

266309
```py
267310
t.field.multivalue_field.all_values = ["AAA", "BBB"]
268311
```
269312

313+
</TabItem>
314+
</Tabs>
315+
270316
### Create enum field options
271317

272-
#### Formula field
318+
<Tabs groupId="rossum-formulas-flavor">
319+
<TabItem value="formula_field" label="Formula field" default>
273320

274321
:::warning
275322

276-
Changing enum field options is currently not supported in formula fields.
323+
Changing enum field options is currently not supported in formula fields (only serverless functions).
277324

278325
:::
279326

280-
#### Serverless function
327+
</TabItem>
328+
<TabItem value="serverless_function" label="Serverless function">
281329

282330
```py
283331
t.field.enum_field.attr.options = [{"label":"AAA", "value":"aaa"}, {"label":"BBB", "value":"bbb"}]
284332
t.field.enum_field = "bbb"
285333
```
334+
335+
</TabItem>
336+
</Tabs>

0 commit comments

Comments
 (0)