Skip to content

Commit 5f87b93

Browse files
committed
update
1 parent c197d62 commit 5f87b93

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ This command generates static content into the `build` directory and can be serv
4444
Very handy for Gemini gems:
4545

4646
```bash
47-
find ./docs -name "*.md" | xargs cat > ./all_handbook_content.txt
47+
find ./docs ./cookbook -name "*.md" | xargs cat > ./all_handbook_content.txt
4848
```

all_handbook_content.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14282,3 +14282,83 @@ It might be necessary to have **manual** PO number overwrite on header fields. I
1428214282
]
1428314283
}
1428414284
```
14285+
---
14286+
title: Multiple data matching results
14287+
slug: multiple-data-matching-results
14288+
authors: [mrtnzlml]
14289+
tags: [master-data-hub, rossum-formulas]
14290+
---
14291+
14292+
import QuizComponent from '@site/src/components/QuizComponent';
14293+
14294+
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?
14295+
14296+
<!-- truncate -->
14297+
14298+
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`:
14299+
14300+
```python
14301+
from txscript import TxScript, default_to, substitute
14302+
14303+
14304+
def rossum_hook_request_handler(payload):
14305+
x = TxScript.from_payload(payload)
14306+
14307+
# Do not recalculate if the input data has not changed
14308+
# (add more fields depending on the input into your MDH query):
14309+
recalculate_hash = f"{x.field.order_id}__{x.field.grn_id}"
14310+
if x.field.recalculate_hash == recalculate_hash:
14311+
return x.hook_response()
14312+
14313+
# Get all valid enum options (result of the MDH query):
14314+
order_line_options = default_to(x.field.order_id_match.attr.options, [])
14315+
valid_options = [
14316+
opt for opt in order_line_options if opt.value
14317+
]
14318+
14319+
# Clear existing multivalue table:
14320+
x.field.order_id_lines = []
14321+
14322+
# Create new multivalue table:
14323+
new_lines = []
14324+
for option in valid_options:
14325+
new_lines.append({
14326+
"order__id": option.value
14327+
# What about other columns? Keep reading. :)
14328+
})
14329+
14330+
# Insert new values into the multivalue table:
14331+
x.field.order_id_lines = new_lines
14332+
x.field.recalculate_hash = recalculate_hash
14333+
14334+
return x.hook_response()
14335+
```
14336+
14337+
The function does the following:
14338+
14339+
1. Get all valid options from the `order_id_match` enum field.
14340+
2. Clear the existing `order_id_lines` table (our destination).
14341+
3. Insert the enum values into the `order_id_lines` destination table.
14342+
14343+
Additionally, it takes care of recalculating the table lazily so users can update the final table manually if needed (see the `recalculate_hash` field).
14344+
14345+
This way, all data matching results were populated into multivalue table despite the data matching supporting only enum fields.
14346+
14347+
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:
14348+
14349+
```text
14350+
.---------. .--------------------------. .---------.
14351+
| MDH 1 | ---> | Custom hook from above | ---> | MDH 2 |
14352+
`---------` `--------------------------` `---------`
14353+
```
14354+
14355+
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.
14356+
14357+
<QuizComponent
14358+
question="Can master data hub extension return values to a string field?"
14359+
answers={[
14360+
{ text: 'Yes, MDH can return values into any preconfigured field' },
14361+
{ text: 'No, only enum fields are supported', isCorrect: true }
14362+
]}>
14363+
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.
14364+
</QuizComponent>

0 commit comments

Comments
 (0)