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

Community Alums
Not applicable

Hey @KeithM1 

 

The issue seems to be you have double quotes around "true" and "false". Take those out and set the value to the boolean true/false and you should be good to go.

 

Hope this helps!

~Nick

I tried it with no quotes and with single quotes and no luck

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");
    }

Data Type Check on the u_active Field: Make sure that u_active is a boolean or true/false type field in the dictionary. If this field was created as a string or some other type by mistake, it wouldn't work with true/false.

 

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