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.

 

FAQs


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

 

Q. What coding language is used in Transform Scripts?

A. PHP JavaScript

 

 

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

Comments