setting a value using transform script

KeithM1
Tera Expert

I'm importing some department data and there is a custom field called Active.  It is a checkbox.  The data coming from the source shows either Active or Inactive.  If the status is Active, I need the custom field to be checked.  If it is Inactive, I need it to be unchecked.  I've created an onAfter transform script but it isn't setting the value after the import.  Here's the script I'm using:

    if (source.u_status == "Active"){
        gs.info("Source status: " + source.u_status);
        target.u_active="true";
        gs.info("End active if");
       
    } else if (source.u_status == "Inactive"){
        gs.info("Source status: " + source.u_status);
        target.u_active = "false";
        gs.info("End active if");
    }
 
When I look in the logs, it gets the value correctly from the source, it just isn't setting the target value.  I'm not sure what I'm missing.  I'm open to suggestions.
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hey @KeithM1 

 

Is there any particular reason you are doing this in an onAfter instead of just in a field map? It might be more straight forward to do it that way. Setup a field mapping for the field u_active, check the box for "Use source script", then plug in your script with slight modification:

 

if (source.u_status == "Active"){
        gs.info("Source status: " + source.u_status);
        return true;
    } else if (source.u_status == "Inactive"){
        gs.info("Source status: " + source.u_status);
        return false
    }

 

Hope this helps!
~Nick

 

View solution in original post

6 REPLIES 6

I hadn't thought about doing it that way.  It worked perfect.  Thank you!!

Rajesh Chopade1
Mega Sage

Hi @KeithM1 

Replace target.u_active = "true"; with target.u_active = true; (and similarly for "false" to false). This ensures that you are assigning a boolean value instead of a string.

 

Thank you

Rajesh