Skip to content

Commit 102606d

Browse files
committed
update
1 parent ae6c40d commit 102606d

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Multiple data matching results
3+
slug: multiple-data-matching-results
4+
authors: [mrtnzlml]
5+
tags: [master-data-hub, rossum-formulas]
6+
---
7+
8+
import QuizComponent from '@site/src/components/QuizComponent';
9+
10+
Data matching (Master Data Hub; MDH) results are by default returned into an "enum" field in Rossum (also known as "Options" field). Enum field allows to select only one of the values returned (it behaves as a regular [HTML select element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/select) with options). What if you need to select multiple values, however?
11+
12+
<!-- truncate -->
13+
14+
The solution is to return all values into a **hidden** enum field and later process the data using a simple serverless function. In our example, the hidden field is `order_id_match`:
15+
16+
```python
17+
from txscript import TxScript, default_to, substitute
18+
19+
20+
def rossum_hook_request_handler(payload):
21+
x = TxScript.from_payload(payload)
22+
23+
# Do not recalculate if the input data has not changed
24+
# (add more fields depending on the input into your MDH query):
25+
recalculate_hash = f"{x.field.order_id}__{x.field.grn_id}"
26+
if x.field.recalculate_hash == recalculate_hash:
27+
return x.hook_response()
28+
29+
# Get all valid enum options (result of the MDH query):
30+
order_line_options = default_to(x.field.order_id_match.attr.options, [])
31+
valid_options = [
32+
opt for opt in order_line_options if opt.value
33+
]
34+
35+
# Clear existing multivalue table:
36+
x.field.order_id_lines = []
37+
38+
# Create new multivalue table:
39+
new_lines = []
40+
for option in valid_options:
41+
new_lines.append({
42+
"order__id": option.value
43+
# What about other columns? Keep reading. :)
44+
})
45+
46+
# Insert new values into the multivalue table:
47+
x.field.order_id_lines = new_lines
48+
x.field.recalculate_hash = recalculate_hash
49+
50+
return x.hook_response()
51+
```
52+
53+
The function does the following:
54+
55+
1. Get all valid options from the `order_id_match` enum field.
56+
2. Clear the existing `order_id_lines` table (our destination).
57+
3. Insert the enum values into the `order_id_lines` destination table.
58+
59+
Additionally, it takes care of recalculating the table lazily so users can update the final table manually if needed (see the `recalculate_hash` field).
60+
61+
This way, all data matching results were populated into multivalue table despite the data matching supporting only enum fields.
62+
63+
Note that it might be a good idea to lazily load additional values in the table. In real-world solution, the chain of hooks would look like this:
64+
65+
```text
66+
.---------. .--------------------------. .---------.
67+
| MDH 1 | ---> | Custom hook from above | ---> | MDH 2 |
68+
`---------` `--------------------------` `---------`
69+
```
70+
71+
This way, we can distribute only row IDs from the first MDH extension and load the actual data in the second MDH extension. Alternatively, we could populate all the data in the first MDH hook. That is however a bit laborious when there are many columns to populate and distribute.
72+
73+
<QuizComponent
74+
question="Can master data hub extension return values to a string field?"
75+
answers={[
76+
{ text: 'Yes, MDH can return values into any preconfigured field' },
77+
{ text: 'No, only enum fields are supported', isCorrect: true }
78+
]}>
79+
The only field type that Master Data Hub (MDH) extension supports are `enum` fields. Enum fields limit the section to only one specific value. However, we can still access all the values (options) using the `x.field.order_id_match.attr.options` code which can later be distributed into a multivalue table.
80+
</QuizComponent>

cookbook/authors.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mrtnzlml:
2+
name: Martin Zlámal
3+
title: Solution Architect
4+
url: https://github.com/mrtnzlml
5+
image_url: https://github.com/mrtnzlml.png

cookbook/tags.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
master-data-hub:
2+
label: 'master-data-hub'
3+
4+
rossum-formulas:
5+
label: 'rossum-formulas'

docusaurus.config.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ const config = {
4949
sidebarPath: './sidebars.js',
5050
editUrl: 'https://github.com/mrtnzlml/rossum-sa-handbook/tree/master/',
5151
},
52-
blog: false,
52+
blog: {
53+
// Will be passed to @docusaurus/plugin-content-blog (false to disable)
54+
path: 'cookbook',
55+
routeBasePath: 'cookbook',
56+
blogTitle: 'Cookbook',
57+
blogDescription: 'Cookbook',
58+
blogSidebarCount: 0,
59+
showReadingTime: false,
60+
},
5361
theme: {
5462
// Will be passed to @docusaurus/theme-classic.
5563
customCss: './src/css/custom.css',
@@ -95,11 +103,11 @@ const config = {
95103
// },
96104

97105
// http://localhost:3000/blog
98-
// {
99-
// to: '/blog',
100-
// label: 'Blog',
101-
// position: 'left',
102-
// },
106+
{
107+
to: '/cookbook',
108+
label: 'Cookbook',
109+
position: 'left',
110+
},
103111

104112
{
105113
href: 'https://elis.rossum.ai/api/docs/',

0 commit comments

Comments
 (0)