Export/Lookup Javascript Transformations
I'm working in the new UI and would like to try the new Javascript transformation on exports/lookups, but I haven't found much documentation on them. I have some transformations that I think would be easier implemented in JS than through handlebars statements. Is there anything available that documents how to use that feature?
-
Hi Wade Shelton,
Thanks for letting us know about this need! We don't have any docs on that specifically yet. Are there any particular questions you have? We'll work on getting some docs ready as soon as we can.
0 -
Courtney -
I'm just trying to understand the syntax for the rules. In other places where you can interject Javascript, you can insert function stubs so that you can determine what the parameters and returns look like. There's nothing here for this feature, so I can't determine the object being passed or what should be returned.
0 -
Hi Wade,
You can insert a stub once you choose the script file.
Here I haven't selected the script (note the "None" selection):
... and once I select a script, I can insert the transform stub.
And just in case, here's the stub:
/*
* transformFunction stub:
*
* The name of the function can be changed to anything you like.
*
* The function will be passed one 'options' argument that has the following fields:
* 'record' - object {} or array [] depending on the data source.
* 'settings' - all custom settings in scope for the transform currently running.
* The function needs to return the transformed record.
* Throwing an exception will return an error for the record.
*/
function transform (options) {
return options.record
}0 -
And here's a working example I made (testing the limits of my own rudimentary JS skills):
0 -
Hey, does this feature work? My code is not saving when I try to use a JS transform
Edit: your function must return "record" - no other return is accepted. That was not super clear first time around :)
2 -
Hi Walt -
Thanks for updating this post with that information. We plan to create more documentation on using JavaScript transformations for exports and lookups. Please tell us more about your use case when you have a minute. (And that goes for anyone else reading this too!) It's very helpful to our team so that we can document useful examples.-1 -
Thanks Kate! I am using the JavaScript transformation to pull certain timestamps out of an array that is not guaranteed to be sorted. This is using the EasyPost tracker API response. This feature is definitely light on docs at the moment, would greatly appreciate more guidance in the future!
Here is the code I ended up with:
function transform(options) {
let input = options.record
let tracking_details = input["tracking_details"]
var shipment_created_date = null
var actual_picked_up_date = null
var actual_delivered_date = null
for (var i = 0; i < tracking_details.length; i++) {
if (tracking_details[i]["status_detail"] === "label_created") {
shipment_created_date = tracking_details[i]["datetime"]
}
if (tracking_details[i]["message"] === "Picked up") {
actual_picked_up_date = tracking_details[i]["datetime"]
}
if (tracking_details[i]["status"] === "delivered") {
actual_delivered_date = tracking_details[i]["datetime"]
}
}
var record = {
"shipment_created_date" : shipment_created_date
,"actual_picked_up_date" : actual_picked_up_date
,"actual_delivered_date" : actual_delivered_date
,"estimated_delivered_date" : input["carrier_detail"]["est_delivery_date_local"]
}
return record
}0 -
Thanks, Walt Laws-MacDonald. We really appreciate the code example.
0 -
Celigo: Define transformation.
Hi Celigo, I've over 70 records in the input section, but only the LAST record is displayed in the output, and it was successfully inserted in the destination table inside SSMS.
I need advice on how to have all 70 records listed in the output section, so that I can have all records inserted into the destination table.
0 -
Hello Babatunde Dallas
Could you add "*." to all the fields on the right side?
Example - change Location_Code to *.Location_Code
Thanks!0 -
Hi
I am integrating workday to netsuite we used post method and its running good for multiple records and for single record we are getting evaluation failed invalid transformation error.what i understand in debugging for multiple we have square brackets i mean array that s its passing records for single object we are not getting square bracket and we have only curly brackets.please let me know its urgent.
0
Please sign in to leave a comment.
Comments
11 comments