Datamapper Javascript expression

Hi,

I want something quite simple in Datamapper but I can’t find a way to make it work.
In designer if statements work,but in javascript expressions it won’t

record.fields.sexeaanhef = record.fields.GESLACHT;

if (record.fields.sexeaanhef == "m"){
    record.fields.sexeaanhef.replace("m", "Geachte heer");
}
![](https://learn.objectiflune.com/qa-blobs/2025351903222963232.jpeg)

Also, is there a easy way to use .properCase in the datamapper? in designer it works fine.

If you do the same in an Action Step, it should work.

What also would work in that extraction step:

var titel = record.fields.GESLACHT;

if (titel == "m") {

titel.replace("m", Geachte heer");

}

this doesn’t seem to work for me, what am I doing wrong?

i declare a variable brief_aanhef, but how can i use this variable?
I tried to make it in record.fields.brief_aanhef, but nothing happens.

what’s wrong with this picture?

your script would work in an extraction step, but not in an action step.

In an action step you need to do an assignment like:

record.fields.sexeaanhef = brief_aanhef.replace(….);

to assign the result of replace() to record field sexeaanhef (but which needs to be already available from a previous extraction step or if it’s a custom field).

Whereas in an extracton step the last string expression of a script would be assigned to the record field of that extraction, so result of line

brief_aanhef.replace(….);

would be assigned to field sexeaanhef (if that is the recrod field of the extraction).

And please note in an extraction step for field sexeaanhef you cannot do

record.fields.sexeaanhef.replace();

because the field object isn’t available at that time (but after the extraction step), hence gives an error when trying to apply method replace().

Thank you for your help, I have the sollution here:

if(record.fields.Geslacht == ‘Vrouw’){
“Mevrouw”;
}