Delivery Transform Scripts

Follow

Our Transform Scripts tool in LeadByte is an essential tool used to customise and manipulate data during the delivery process. When you need to send lead data to a Buyer, the way the data is stored in LeadByte might not always match the format required by the receiving party. Transform scripts come into play by enabling you to modify this data, ensuring it meets the Buyer's specifications.


When would I use Transform Scripts?

You can use Transform Scripts in multiple scenarios. The possibilities are endless, but some common options include:

  • striping characters from field values
  • adding characters to field value

Example Scripts

Whilst we do not have a library of scripts available for you to use, we have provided a few examples below for the sake of formatting:

 

Script 1 - Postcode is always 5 digits

var main = function(data) {

if(data.postcode) {
// If the postcode is longer than 5 digits, remove the excess
if(data.postcode.length > 5) {
data.postcode = data.postcode.substring(0, 5);
}
// If the postcode is shorter, add leading zeros
else {
while(data.postcode.length < 5) {
data.postcode = '0' + data.postcode;
}
}
}
}

This JavaScript script normalises postal codes (postcode) within a data object to ensure they are always 5 digits long:

  • Trims: If the postcode is longer than 5 digits, it trims it to the first 5.
  • Pads: If it's shorter, it adds leading zeros until it reaches 5 digits.
  • Returns: The modified data object is then returned.

Examples:

  • "123456" becomes "12345".
  • "123" becomes "00123".
  • "12345" remains unchanged.

Please note: When targeting custom data fields inside a transform script, it is important that you must target these fields with data.data# instead of data.labelname - the transformation will not work live unless you target the data number instead of the label.

FAQs


Q. Where do I add Transform Scripts for my Deliveries?
A. You can add Transform Scripts under Tech Hub> Transform Scripts. You will then need to add them to the relevant Delivery under Advanced Settings here
 

Q. Why can I not see the transform script menu?
A. By default, accounts do not have access to the transform scripts - if you do not see the transform script menu under Tech Hub> Transform Scripts - please raise a ticket with support so we can add it to your account.
 

Q. What coding language is used in Transform Scripts?

A. PHP JavaScript

 

Q. Why are my custom data fields not being correctly transformed on my delivery?

A. When targeting custom data fields, for example if I was trying to transform a custom field called stats which is also data1, you need to target data.data1 in your script instead of data.stats

 

Q. Why is it not reading the data stored in some of my fields when performing transformations?

A. If you wanted to perform a translation using the street1 value and outputting in a different field, you must include the [street1] tag in your delivery payload so it is available to be used. If the [street1] tag is missing, the data cannot be read. If you do not want to include the original street1 data into the delivery payload, you should perform the translation to output into the [street1] tag itself so the tag can be included but translated, changing the original value instead of outputting it into a separate field.

 

 

Was this article helpful?
0 out of 0 found this helpful

Comments