Some mapping changes need a little JavaScript: adding a fixed custom field, adding a tag to every order, or shortening a field that's too long for the other system. This article walks through three examples. Before you start, read Customizing mappings in Pipe17, which explains how mappings work and the [$0] array syntax.
In each example you change the source of an existing baseline mapping and keep its target. Pipe17 saves your version as a custom override, and the baseline stays available to revert to. To edit a source as code, open the integration's Mappings tab, find the row, and click the code icon (<>) next to its source. The Edit code window opens; make your change and click OK. Test with Test before you click Save changes, because the test uses your unsaved changes.
Add a custom field
Say you want every order from Amazon Seller Central to carry a custom field that says where it came from: name sourceChannel, value amazonSC.
- Go to Configure > Integrations, open your Amazon Seller Central integration, and select the Mappings tab.
- Select Orders and From Amazon Seller Central.
- Find the row whose target is Custom Fields (
customFields) and click its code icon. The baseline source builds a list of{ name, value }pairs from Amazon order fields, and returns nothing when none of those fields has a value. -
Wrap the baseline source in parentheses, add
|| []so it's always a list, and add your field with.concat():(<baseline source> || []) .concat({ name: 'sourceChannel', value: 'amazonSC' }) - Click OK, then click Test. Paste a sample order into Editable JSON Input (or click Load most recent) and click Test mappings. JSON Output now lists
sourceChannelundercustomFields. - Click Cancel to close the test, then Save changes.
The || [] matters: without it, an order with none of the baseline fields would make the rule fail, and the order would get no custom fields at all.
Add an order tag
Order tags work the same way. This example adds the tag Pipe17 to every Shopify order. In Pipe17, tags are a list of text values, for example ["Tag1", "Tag2"].
- Open your Shopify integration's Mappings tab and select Orders and From Shopify.
-
Find the row whose target is Tags (
tags) and click its code icon. The baseline splits the Shopify tags on commas, adds the order's source name, trims spaces, and removes blanks and duplicates:tags.split(',').concat(...[sourcedoc.source_name]).map(x => (x || '').trim()).filter((x,i,a) => x && a.indexOf(x) === i).reduce((r,x,i,a) => a, undefined) -
Replace it with this version, which also adds
Pipe17and still works when an order has no tags:(sourcedoc.tags || '').split(',').concat(sourcedoc.source_name || '', 'Pipe17').map(x => x.trim()).filter((x, i, a) => x && a.indexOf(x) === i) - Click OK, then Test. With a sample order that has the tags
ABC, DEF, JSON Output shows the tags ABC, DEF, the source name, and Pipe17. - Close the test and click Save changes.
Using sourcedoc.tags || '' instead of tags keeps the rule working on orders without tags. If a rule throws an error, Pipe17 drops that whole field from the order.
Shorten a field
Say you push products from Pipe17 to Logiwa, and Logiwa rejects a product because its description is longer than Logiwa allows. You have two options:
- Shorten the description in the sales channel the product came from, pull the product into Pipe17 again, and push it again. We recommend this, because it keeps your systems consistent.
- For a quick fix, shorten the description in the mapping so it never goes over the limit.
For the quick fix, open your Logiwa integration's Mappings tab and select Products and To Logiwa. Find the row whose target is description and change its source to the following, using Logiwa's limit (500 in this example):
sourcedoc.description?.slice(0, 500) || '-'This keeps the first 500 characters and, like the baseline, sends - when a product has no description.
Troubleshooting
- The field I changed is missing from the test output.
The rule probably threw an error, so Pipe17 dropped the field. Click Copy error details in the test window to see why. Common causes are calling a method on a missing value (usesourcedoc.field || ''or?.) or a typo. - The test shows "N of your mapping rules failed to execute".
Your sample document may be missing fields other rules need. Use Load most recent or a real record ID to test with a complete document. - I want the original mapping back.
Click the Revert mapping to default icon on the row, then Save changes. You can also use ⋮ > Compare mappings to restore an earlier version.
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