The Shipping Request Transformer runs your own JavaScript on each shipping request the Order Routing Engine creates, after routing picks a location and before the request is sent to that location. Use it to change fields that routing rules can't set, such as the carrier, shipping method, notes or custom fields, based on the order or the location. Routing decisions stay as the engine made them. If your code fails or Pipe17 rejects the result, Pipe17 tries to create the original shipping request instead and raises a Transformation Failure exception. The original can still be rejected; see When the code fails.
Before you start
- Availability. The Transformers tab is on the Order Routing Engine page and is turned on per organization. If you don't see it, contact Pipe17 Support.
- Permissions. To see Order Routing in the menu, your role needs Read and List for Routings. To turn the transformer on, edit or test the code, or save, you need Update for Integrations. Without it, the page is read-only. See Managing Roles and Permissions.
- Skills. You need basic JavaScript. The code runs in a sandbox and can only read the three variables described in Write the code.
How it works
- The Order Routing Engine routes the order with your routing rules and builds a shipping request for each fulfillment location.
- If request transformation is on and code is saved, your code runs once for each of those shipping requests. A run that creates three shipping requests runs the code three times.
- Pipe17 creates the shipping request your code returns and sends it to the fulfillment location.
The transformer is skipped when Enable request transformation is off, when no code is saved, or when the run creates no shipping requests. Saving new code only affects future routing runs; it doesn't change shipping requests that already exist.
Keep in mind:
-
The returned object replaces the shipping request. It isn't merged. Any field you leave out is removed. Change the
shippingRequestyou're given and return it, rather than building a new object with only the changed fields. - Some fields can't be changed. See Fields you can't change. To send an order to a different location, change your routing rules instead.
- Failures fall back to the original. See When the code fails.
Turn on request transformation
To turn on the transformer:
- Go to Order Routing, open the Order Routing Engine, and select the Transformers tab.
- In Shipping Request Transformer, turn on Enable request transformation. The Transformation JS code editor opens with a starter template that returns the shipping request unchanged.
- Write your code (see Write the code), then test it (see Test your code).
- Click Save changes. The card shows Unsaved changes until you save or cancel.
- In Add Change Reason, enter a reason if your organization requires one, then click Submit. A Transformer saved message confirms the save. Clicking Cancel in this dialog leaves the changes unsaved.
To discard unsaved edits, click Cancel on the card. The switch and the code go back to the last saved version.
Write the code
Your code is the body of a function. It can use these variables and must return the shipping request as an object.
| Variable | What it holds |
|---|---|
order |
The full order being routed. |
shippingRequest |
The shipping request to transform. Change it and return it. |
location |
The fulfillment location your routing rules selected. |
Changing order or location doesn't update those records; only the returned shipping request is used. If the code returns nothing, or returns something that isn't an object, it counts as a failure and the original shipping request is sent.
The editor suggests property names as you type. Hover the help icon next to Transformation JS code to see the variables.
Examples
Use FedEx 2Day for orders tagged EXPRESS (replace the carrier and service values with ones your fulfillment location supports):
if (order.tags && order.tags.includes('EXPRESS')) {
shippingRequest.shippingCarrier = 'FedEx';
shippingRequest.shippingCode = 'FEDEX_2_DAY';
}
return shippingRequest;Copy the order source into a custom field, keeping the existing custom fields:
shippingRequest.customFields = [
...(shippingRequest.customFields || []),
{ name: 'originalOrderSource', value: order.orderSource },
];
return shippingRequest;Whether the fulfillment location receives a custom field depends on its connector and mappings.
Fields you can't change
If your code changes or removes one of these fields, Pipe17 restores the original value and keeps the rest of your changes. The routing run records which field was protected.
| Group | Fields |
|---|---|
| Routing and relationships |
orderId, locationId, fulfillmentIntegrationId, integration, orderIntegration
|
| Identifiers and timestamps |
shipmentId, createdAt, updatedAt, version, orderCreateTime
|
| System-managed data |
autoEngUpdateStatusUpdatedAt, exceptionCategories, sourceDoc, timeline
|
Test your code
Test with a real order and location before you save. Testing runs the code only. It doesn't change the order, create a shipping request or save the transformer.
To test your code:
- Under the code editor, click Test code. The Test Shipping Request Transformer Code dialog opens.
- Under Specify an order for testing, click Load most recent order, or enter an order ID in Enter OrderID and click Load.
- Under Specify a location for testing, select a location.
- Review Input Variables (
order,location,shippingRequest). You can edit this JSON to try other cases. Edit the code in the Code panel if needed. - Click Test code. The result appears under Output, or Error with the message if the code throws. Any
console.loglines appear under Debug Output. - Click Close. The code from the dialog is copied back to the editor. Click Save changes to keep it.
Notes:
- Test code is available only after an order and a location are loaded. Testing can also be turned off for a while. The button then shows Code test temporarily disabled. Saved transformers still run.
- If your code changes a protected field, a warning names the fields and says the original values will be preserved.
- Clear all content clears the code, inputs and output in the dialog. If you then click Close, the editor is cleared too; click Cancel on the card to get the saved code back.
- A successful test doesn't guarantee that Pipe17 or the fulfillment location will accept the shipping request. Check the first live routing runs after you save.
Check routing runs and logs
Each routing run records what the transformer did in its Final Summary. To see it, open Order Routing > Routing Runs, find the order and click its Run ID. See Order Routing Runs.
| Message | Meaning |
|---|---|
| Applying Shipping Request Transformer to N shipping requests | The transformer ran. |
| Shipping Request Transformer modified shipping request for location … | Your changes were applied. |
| Shipping Request Transformer ran successfully but made no changes … | The code ran and returned the same request. |
| Shipping Request Transformer attempted to modify protected field … | A protected field was restored. |
| Shipping Request Transformer failed for location … Using original data. | The code failed; the original was used. |
| Transformed shipping request rejected by API … Retrying with original payload. | Pipe17 rejected your result; the original was used. |
| Transformer log: … | A line your code printed. |
To log values from your code, use console.log, console.warn or console.error. Each line appears as a Transformer log message in the run, and under Debug Output when you test. Don't log sensitive customer data.
When the code fails
Each shipping request in a run is handled on its own, so one failure doesn't affect the others.
| Situation | Result |
|---|---|
| The code throws an error or doesn't return an object | The original shipping request is sent. |
| Pipe17 rejects the transformed shipping request (for example, a required field is missing) | Pipe17 retries with the original shipping request. |
| The original shipping request is also rejected | The shipping request isn't created, and no Transformation Failure exception is raised. The routing run shows Error creating shipping request., and the order's routing status can change to failed or partially routed. Check the routing run for the error. |
When the original shipping request is created after a code failure or a rejected result, Pipe17 raises a Transformation Failure exception on that shipping request, linked to the order. It tells you your changes weren't applied; the shipping request itself still goes to the location. See Order Exception Engine.
To fix a Transformation Failure:
- Open the routing run for the order and read the error in Final Summary.
- Click Test code on the Transformers tab, load the same order and location, and fix the code until the test passes.
- Click Save changes.
- Check the shipping request that was already sent. Saving the fix doesn't change it. First check whether the location has already started fulfilling it. If it hasn't, and the location still needs the corrected values, update the shipping request. Rerouting a request the location is already working on can create duplicate fulfillment work.
Turn off or roll back the transformer
To turn the transformer off:
- On the Transformers tab, turn off Enable request transformation.
- Click Save changes and complete Add Change Reason.
The saved code is kept but isn't run. New shipping requests are sent without changes.
There is no rollback button. To go back to an earlier version, paste that code into Transformation JS code, test it and save. Keep a copy of working code before you replace it.
Troubleshooting
-
I don't see the Transformers tab
The tab is turned on per organization; contact Pipe17 Support. Also check that your role has Read and List for Routings. -
The switch, Test code or Save changes is disabled
Your role needs Update for Integrations. Save changes is also disabled until there are unsaved changes, and Test code in the dialog needs an order and a location loaded. -
Test code shows "Code test temporarily disabled. Saved transformers still run."
Testing is turned off for now. Your saved transformer keeps running on new shipping requests. Try testing again later, and check live routing runs in the meantime. -
Shipping requests are sent without my changes
Check that Enable request transformation is on and saved, and that your condition matches the order. Then check the routing run and the shipping request for a Transformation Failure exception. -
Test shows "Error: It was not possible to execute the code"
Check the code for syntax errors and make sure it ends withreturn shippingRequest;. -
A field I set didn't change
It's a protected field. The routing run names it. To change the shipping location, update your routing rules. -
Fields are missing after transformation
The returned object replaces the shipping request. Change theshippingRequestvariable and return it instead of returning a new object. -
The test passed but live shipping requests fall back to the original
The test doesn't validate the result with Pipe17. Read the "rejected by API" message in the routing run and fix the payload. -
"Unable to save transformer" appears
Check your permissions and try again. Reopen the tab to confirm what's saved.
Need Help?
If you need additional assistance:
- Use Ask Pippen, our AI agent, located at the top of the platform page.
- Submit a support request with as much relevant detail as possible. Learn how to submit a request.
We're here to help you succeed with your operations.
Comments
0 comments