Need to modify the field script

suuriyas
Tera Contributor

HI Community,

 

I have written a field script in transform map, when class is t/a/ga/e then it should update as 'e'  which is working fine but when there is empty value from source then it should not update as e or ext currently i guess it if the class is empty then it is updating as ext but it should update as empty 

 

How can i modify the script:

answer = (function transformEntry(source) {

   
    var zone = source.u_employee_class; // (u_employee_class is the field in source table)
    if (zone == "T" || zone == "A" || zone == "GA" || zone == "E") {
        return "E";
    } else
        return 'EXT';

})(source);
10 REPLIES 10

What type of field is

source.u_employee_class

Are you sure it is empty and not containing some value?

HI @sergiu_panaite ,

 

Yes in source table i checked that particular field (employee class) it is single line field and for some records we are receiving empty value.

In employee class field (source table) we will be receiving values as A T GA E EXT and empty so now for empty it is updating as ext it should update as none

In transform map, HR profile is the target table and we are mapping the employee type field in hr profile with this field script.

 

HR Profile field:

suuriyas_0-1749030862322.png

 

Hristo Ivanov
Kilo Sage

you can try this

answer = (function transformEntry(source, target /*, map, log, action*/) {

    // normalise the incoming value
    var zone = (source.u_employee_class || '').toString().trim().toUpperCase();

    // ─── 1. no value in the source  ──────────────────────────────────────────────
    if (!zone) {
        return '';                 // leave the target field blank
        // ─or─  return target.u_employee_class;   // keep whatever it already had
    }

    // ─── 2. T / A / GA / E  →  "E"  ────────────────────────────────────────────
    if (zone === 'T' || zone === 'A' || zone === 'GA' || zone === 'E') {
        return 'E';
    }

    // ─── 3. anything else  →  "EXT"  ───────────────────────────────────────────
    return 'EXT';

})(source, target);

@suuriyas  did you try this?

HI @Hristo Ivanov ,

 

Thanks for your response, but i don't understand the script.

 

I have written a field script and map it to the employee class in hr profile table ( target table).

In source table i checked that particular field (employee class) it is single line field and for some records we are receiving empty value.

In employee class field (source table) we will be receiving values as A T GA E EXT and empty so now for empty it is updating as ext it should update as none

In transform map, HR profile is the target table and we are mapping the employee type field in hr profile with this field script.