how to use on before script in transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2023 11:43 AM
Hi,
I have the fields in my table:
u date of type date
u_hour of type numeric
u_campaign of type string
u_display_name of type string
in my xlsx file which im using to load data i only have u_date, u_hour and u_campaign.
the field u_display_name (does not exist in the xlsx file) should be the Coalesce and it should be auto populate before the transform map run by the combination of u_date + u_hour + u campaign.
How can I achieve that? can anyone help me with the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2023 12:54 PM
Hello Alon,
You can concatenate the available fields and set it to the u_display_name field.
Configure onBefore Transform Script something like this:
function onBeforeTransform(current) {
// Combine the values of u_date, u_hour, and u_campaign to form the value for u_display_name
current.u_display_name = current.u_date + " " + current.u_hour + " " + current.u_campaign;
return current;
}
And from the field map, you can set 'Coalesce' to true for display name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2023 11:49 PM
@Prasad Dhumal hi but i dont need to change the date and hour to string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 12:06 AM
Hi @Alon Grod ,
If you wish to write Before transform then write below,
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
//Combine the values of u_date, u_hour, and u_campaign to form the value for u_display_name
if(source.u_display_name == ""){
target.u_display_name = source.u_date + " " + source.u_hour + " " + source.u_campaign;
}
})(source, map, log, target);
Also,
You can try for after transform script as well.
Could be same as above for after just remember to add target.update(); in after transform script.
If it helps to resolve your issue, please mark correct
Thanks,
Pratik Malviya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 12:23 AM - edited 01-30-2023 12:36 AM
Hi @Prasad Dhumal ,
If you wish to populate u_display_name with the combination of u_date+u_hour+u_campaign, you can do as below to set the coalesce
Go to field maps and select script and the target field as u_display_name and make the coalesce checked
In the script do as follows:
var name = source.u_date + " " + source.u_hour + " " + source.u_campaign;
return name;
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.