transform map script to set field value

tscoggin
Giga Contributor

We are trying to set a field value to "True" before the data is added to the target table. The imported data does not have a value for the field but the field does exist on the Import Set Table. So the question is how can we set a records value or a field before inserting it into the target table.

My attempt

When "onBefore"

Transform Scripts:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

// Add your code here
If (activity == 'insert' || activity == 'update');
target.import_flag = "true";

})(source, map, log, target);

1 ACCEPTED SOLUTION

When I added a gs.info line I found that the system wanted me to declare field as a variable. When I did that the value was accepted.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

      var u_import_flag ='';


      target.u_import_flag = true;

})(source, map, log, target);

View solution in original post

5 REPLIES 5

Tom Sienkiewicz
Mega Sage

That would actually be

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

// Add your code here
if (action == 'insert' || action== 'update'){
target.import_flag = true;
}

})(source, map, log, target);

Not sure if you need the action part, it will probably always be either insert or update...

Still not changing the value of import_flag to "true". Could it be because the column is not on the import data but only on the import set table? 

Do I need to select run script? I didn't because this script was under the "Transform Scripts" tab and not in the main body of the Transform Map form.

So does that "import_flag" field actually exist on the target table? I'm getting slightly confused but hoping you are trying to update that field on an actual target table...

And is this the correct field name? (asking this as usually custom fields begin with u_ unless they are scoped fields).

You don't need to select the Run Scripts checkbox in your transform map for this to work.

If all the above seems correct, can you verify if there are any Data Policies defined for that table which might prevent the update of the field?

 

Yes the u_import_flag is on the target table and the import set table and mapped in the transform map table to the u_import_flag field. 

As for the data policies, I can update other fields just not the u_import_flag field.

(I noticed that the u_ was missing before you said something. LOL)