PC1.2: How to derive/prepare multiple values from original fields in one step?

Ok - difficult to put that in one sentence…

When the DataMapper is extracting fields, I also get a field ‘gender’, telling me, if the addresse is ‘male’, ‘female’ or ‘unknown’.

Depending on the value, I want to add and set 3 additional fields (not already beeing defined): “salutation”, “salutation_short”, “salutation_letter”:

  • unknown: “”, “”, “Sehr geehrte Damen und Herren”
  • male: “Herr”, “Hr.”, “Sehr geehrter Herr”
  • female: “Frau”, “Fr.”, “Sehr geehrte Frau”

I managed this with one extraction step that extracts 3 fields, whereas the value is detemined by a little piece of JavaScript code for every field.

I noticed that I had to write very similar code 3 times - the only difference was the return value according to the value of field “gender”.

I’d prefer to have only one script, that uses a single switch/case-statement to add and set all 3 fields in one step.

How can this be done?

Horrido,

Thomas

Hello,

If I’m not mistaken, you are trying to add multiple Data model fields with one JavaScript based extraction.

Allthough I would very happy to see this funcionality in the Datamapper, saving me a lot of time on construction and maintenance of several Data models, I don’t think this is possible as of yet. I have searched and experimented with a lot of different constructions which yielded no results.

A possible solution could be the global variables in the Connect Template. This way you can have one Script which fills all the variables you want and you can use them all over your design template, in every Script you make.

The way to do this is creating a new Script in the Scripts pane, and set the selector to body. Then instead of declaring variables using the word ‘var’, you just leave out the word ‘var’ and there’s your Global variable. In your situation it would be something like.

gSalutation = [value]
gSalutation_short = [value]
gSalutation_letter = [value]

These variables are then accesible by every script that follows the script where you declared them. So declaring the global variables is something you want to do as a first (at the top of the scripts). More tips and tricks like this can be found here: https://learn.objectiflune.com/discourse/t/various-tips-tricks-for-connect-designer/269/1

I hope this helps. If someone has a better solution or knows a way to actually add multiple fields with one JavaScript based extraction, please share! I too would love this option.

Regards,
Jelte