I might have found a solution using JS.
Here is my array of objects like this (invoice_pdf_labels):
[
{
“language_id”: 1,
“string_text”: “Frau”,
“tenant_id”: 0,
“pdf_txt_item”: “txt_female_ms”,
“string_id”: 38,
“corresponds_en_string_id”: 3
},
{
“language_id”: 1,
“string_text”: “Bestellung”,
“tenant_id”: 0,
“pdf_txt_item”: “txt_po”,
“string_id”: 39,
“corresponds_en_string_id”: 4
}
]
Example of a JS line sent via the API:
“txt_po”: “Bestellung”,
With the help of AI I created a script for ONE function call per string. Here’s the complete code for my sample array:
// Array of objects (extract)
let invoice_pdf_labels = [{
“language_id”: 1,
“string_text”: “Frau”,
“tenant_id”: 0,
“pdf_txt_item”: “txt_female_ms”,
“string_id”: 38,
“corresponds_en_string_id”: 3
},
{
“language_id”: 1,
“string_text”: “Bestellung”,
“tenant_id”: 0,
“pdf_txt_item”: “txt_po”,
“string_id”: 39,
“corresponds_en_string_id”: 4
}
]
// The following lines are for testing only
// 1. Find the object with the key “txt_po”:
// let pdf_string = invoice_pdf_labels.find(pdf_string => pdf_string.pdf_txt_item === “txt_po”);
// console.log(pdf_string);
// 2. Assign the output value for “string_text” to a variable:
// let xx=“"”+pdf_string.pdf_txt_item + “"” +“: " + “"”+pdf_string.string_text+”"“+”, ";
// console.log(xx);
function extract_pdf_string(lookup) {
let pdf_string = invoice_pdf_labels.find(pdf_string => pdf_string.pdf_txt_item === lookup);
let xx = “"” + pdf_string.string_text + “"”;
return xx;
}
// let lookup = “txt_po”;
// let txt_po = extract_pdf_string(lookup);
let txt_po = extract_pdf_string(“txt_po”);
console.log(txt_po);
// Output is “Bestellung”
This function must be run for each item; the output is assigned to a variable (const) with the same name as pdf_txt_item. It will then be used in the corresponding line, e.g.
“txt_po”: txt_po,
But it would be nicer if this could be achieved in a loop, i.e. the function iterates the whole array and performs these steps automatically (i.e. creates xx for each pdf_txt_item).
Or even better: It produces strings like this one:
“txt_po”: “Bestellung”,
and concatenates the results. The combined output is saved in a single constant which in turn will be used in my JS. Like this:
“txt_po”: “Bestellung”, “txt_order_confirmation”: “Auftragsbestätigung”, …
Meanwhile I don’t think this will work because of the quotation marks. Or could escape be used here?
Anyway, I’m already happy with my solution (it works in WeWeb!). Or do you have a better solution?