CSV Export: Output Value Settings (Default Value, Conditional Branches, Conversion, Code)

plan: Pro plan only (R6)
screens: "Settings" → "CSV templates" → "Edit" of a template → "Field definitions" → "Edit" of a column (the value edit screen)
verified_from: The CSV screen implementation (value edit screen, output engine, token definitions) + the former human-facing manual pages (output values, regular expressions, code, line item properties, metafields), now merged here
ui_verified: Field names were confirmed from the code. Visual confirmation on the real screen has not been done
note: Some order-info item names are shown in Japanese in the English admin. They are written here as the Japanese name plus an English gloss.
related: For the basics of CSV order export see [Pro: CSV order export basics](/en/cc-delivery-date-time/ai/090/csv-basics/)

SUMMARY

The value of one CSV column (one “field”) is decided in three layers: A Default value → B Conditional branches (exceptions) → C Output constraints. For each order, B is evaluated from the top and the value of the first matching branch is used. If none match, A is used. Finally C (the character limit) is applied.

How a value is decided

V-1  Screen structure: the "edit value" screen has three layers.
       A "Default value" … the value used for all orders that match no branch
       B "Branches — exceptions" … evaluated from the top; the value of the first matching branch is adopted. If none match, A
       C "Export" … "Field name" (the column name in the CSV header row) and "Max chars". Applied last to the result of either A or B
V-2  There are two ways to build the value of A:
       "Fixed" … output the same string on every row (example: waybill type "0"). It is not interpreted as order information
       "Detail (order info, code)" … line up one or more of order information, free-typed text and code, and combine them into one cell with a separator
V-3  A line in "Detail" has three kinds: order information (token) / free input (the typed text is output as it is) / code (JavaScript).
V-4  When several lines are lined up, they are joined with "joined by" ("Separator (be)"). The default separator is a comma.
V-5  Only when the "Order info" line is date-type (delivery date, delivery time, order creation date, ship date, Today±N, "Attribute: Key name"),
     "Date format" can be specified (example: YYYY-MM-DD / YYYY/MM/DD / YYYY年M月D日). Only strings that can be converted to a date are formatted.
V-6  "Replacement rules" can be attached only to an "Order info" line (not to free-input or code lines). Several can be added with "Add replacement rule",
     and "Regular expression" lets you use a regular expression for the string before conversion. An invalid regular expression is treated as a literal string.
V-7  For data that has both a fixed value and a Detail value, the Detail (selectVal) takes priority and the fixed value is ignored.
V-8  "Max chars" is the maximum number of characters of the output string. Empty means unlimited.
V-9  A column shown as "Value set by branches" is a column where A is empty and the value is decided only by the branches.
V-10 If you save a branch condition with an empty value, it matches orders in which that item has no value (for the string "contains" method; in the implementation, an empty condition value matches an empty order value).
     Example: a branch with the target field "Delivery Date (App)" and an empty value matches the orders that have no delivery date.
V-11 After choosing the value to output on the branch edit screen, press "Save branch". The choices for the value to output include "Matched value (value of the tested field)" (used in PROC-V7 and PROC-V8).

Main items selectable in “Order info”

On the screen they are divided into the groups “order”, “Customer / Shipping”, “Billing”, “Products”, “Amount”, “Date / Attributes” and “Order attributes (customAttributes)“. Many item names are shown in Japanese; the Japanese name is given with an English gloss.

GroupMain items (display name on the screen)
orderOrder number, order number-ID, Shopify Order ID, order tags, E-mail, order note, discount codes, payment gateway (payment method) name, payment status, fulfillment status, list of excluded product titles
Customer / ShippingPhone number, delivery method, shipping title, shipping recipient first name (配送先氏名(名前)), last name (配送先氏名(苗字)), company, phone, postal code (配送先郵便番号), address, address 1 / 2, country (English)
BillingBilling company, name, phone, postal code, address, address 1 / 2, country
ProductsProduct name, product tags, SKU, variant ID, unit price, line amount (after discounts), quantity ordered, quantity to be fulfilled, line item properties
AmountTotal weight (g), total price, discount amount, total shipping, total tax, subtotal, store credit used, etc. (with items in each currency)
Date / AttributesDelivery Date (App), Delivery Time (App), Delivery method (App), Ship date (App), order creation date, Today-1 / Today+0 / Today+1 / Today+2
Order attributesAdditional details Key / Value, and “Attribute: Key name” for which you specify the Key name on the screen
  • Items such as “Delivery Date (App)” are the delivery date and time that this app wrote with the widget (the order’s “Additional details”).
  • “Discount Codes” are the discount codes used on the order. When there are several, they are joined with the column’s separator (be), the same as tags (”, ” in code variables and judgment targets). Orders without a code are blank. The name of an automatic discount (no code) cannot be output.
  • With “N days from today (custom)” you can specify any number of days for Today+N (negative for the past).
  • Metafields registered in “Order Metafields” under “Settings” → “Fetch settings” appear as options named “Metafield[namespace.key]“. A key that is not registered is not fetched, so it cannot be selected. Fetch again after registering. The same options appear as the target of a conditional branch.

How to build a conditional branch (B)

Form: "If the order's [Field] [method], [value to output]"
Field: the same items as order information (shipping address, product name, product tags, order tags, total price, total weight, Key of additional details, etc.)
Method:
  String … "contains", "does not contain", "contains any", "contains none" (separate several words with commas)
  Number … "Number range (min–max)" (total price, total weight, quantity, etc.)
  Date   … "Date range (YYYY-MM-DD)"
AND   : adding a condition with "Add condition (AND)" makes it match only when all conditions are met
Value to output: Fixed / Detail (order info, code) / "Matched value (value of the tested field)"
Evaluation order: from the top. The first matching branch is adopted (change the order by reordering)

PROC-V1 Output a fixed value (example: always “0” for the waybill type)

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template > "Field definitions" > "Edit" of the target column
Steps:
1. "Settings" → "CSV templates" → "Edit" of the target template
2. In "Field definitions", press "Edit" of the target column
3. In A "Default value" choose "Fixed" and put the value into "Fixed string"
4. "Save" → "Save" in the CSV screen's save bar

PROC-V2 Output order information / join several values (example: surname and given name in one cell)

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template > "Field definitions" > "Edit" of the target column
Steps:
1. "Edit" of the column → choose A "Detail (order info, code)"
2. On the first line choose the last name of the shipping recipient (配送先氏名(苗字))
3. Add a second line with "Add value (combine)" and choose the first name (配送先氏名(名前))
4. In "Separator (be)" put the connecting character (a half-width space or empty)
5. Save

PROC-V3 Replace characters (example: +81 in a phone number to 0)

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template > "Field definitions" > "Edit" of the target column
Steps:
1. "Edit" of the column → in A "Detail" choose the "Phone number" (etc.) line
2. Press "Add replacement rule" under that line
3. Put "+81" as the string before conversion and "0" after conversion
4. To replace with a regular expression, check "Regular expression"
Notes:
- To put characters in when the value is blank (no value), leave "before" empty and specify the characters in "after"
  Example: when you output a total amount with a formula (joining the amount lines with "=" and "+" in "Free text"), attach a replacement rule with "before" empty and "after" set to "0" to the amount line, and orders with no input are output as 0
- Replacement can be attached only to "Order info" lines. Not to free-input or code lines (V-6)
- Splitting a postal code (first 3 digits / last 4 digits) or a phone number is done with a regular-expression replacement. For concrete examples see PROC-V3a

PROC-V3a Convert characters with a regular expression (split a postal code or phone number, separate prefecture and city)

Where: same as PROC-V3 ("Edit" of the column → A "Detail" → an order-info line → "Add replacement rule")
Basics: write a regular expression in the string before conversion and check "Regular expression". If "after" is left empty, the matched part is removed
        (you remove everything except the part you want, so that only the needed part remains)
References (external, JavaScript regular expressions):
  - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
  - Regular expression replacement checker (JavaScript version): https://www.softel.co.jp/labs/tools/replace/
Examples that customers have asked about (before = the regular expression below, after = empty):
1. Split a postal code (999-0000 → 999 and 0000). Output the shipping postal code in 2 columns and attach a replacement rule to each
     First 3 digits (999): -....      (removes the hyphen and the 4 characters after it)
     Last 4 digits (0000): ...-       (removes the first 3 characters and the hyphen)
2. Split a phone number (000-1111-2222 → 000, 1111 and 2222). First put in rules that remove the country code (+81 → 0) and the "-".
   The example assumes that the result is 11 digits:
     First 3 digits:  ........$      (removes the last 8 characters)
     Middle 4 digits: ^...  and  ....$   (two rules: one removes the first 3 characters, the other the last 4)
     Last 4 digits:   ^.......        (removes the first 7 characters)
3. Split the billing (or shipping) address into "prefecture" and "city"
   3-1 Prefecture: not with replacement, but by adding a branch per prefecture in the conditional branches of B
       (example: IF the billing address contains "北海道" (Hokkaido) → value "北海道". Add all 47 prefectures)
   3-2 City: delete the prefecture with replacement rules (leave "after" empty)
       - Delete "日本:" (for Japanese addresses; the order in the source manual: put this first)
       - Replace the regular expression ^(.{2}[都道府県]|.{3}県) with empty (removes the leading prefecture; ".{3}県" covers 神奈川県, 和歌山県 and 鹿児島県)
Notes:
- When the customer does not know regular expressions, or a complex one is needed, guide them to contact the developer (a complex request may be quoted as a separate fee)
- If you only need to extract the prefecture, there is also a way with code (S7 in PROC-V6a)

PROC-V4 Change the value by condition (example: change the cool-delivery class for orders containing frozen food)

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template > "Field definitions" > "Edit" of the target column
Steps:
1. "Edit" of the column → in B "Branches — exceptions" press "Add branch"
2. For "Field" choose "product tags" (or product name), for the method "contains" / "contains any", and as the value "Frozen" etc.
3. Enter the value to output (example: the cool-delivery class value) and press "Save branch"
4. The default value of A is the value for orders that match none
5. Save
Notes:
- Branches are evaluated from the top and the first match is used. Check the order
- To match only when several conditions are all met, use "Add condition (AND)"
- If you save a condition with an empty value, it matches orders in which that item has no value (V-10)
- Example: when the product tags contain "冷凍食品" (frozen food), output "2" in the cool-delivery class column

PROC-V4a Make all the sender columns gift-ready at once

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" on the template > "Basic info" on the right
Prerequisite: the template's "Carrier" (type) is not "Not specified"
Steps:
1. Press "Make the sender gift-ready (N columns)". A modal opens listing each sender column and the billing value it will use
2. Check it and press "Apply all" (press "Cancel" to stop)
3. Press "Save" in the CSV screen's save bar
Notes:
- Only the sender columns (columns named like the carrier's preset) are changed. Columns that already have the gift branch are left as they are
- When every sender column is already gift-ready, this button is not shown
- To choose different values per column, use PROC-V4b ("Add from template" per column) or edit the column's branch

PROC-V4b Output the billing value only when billing and shipping differ (the sender of a gift order)

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the template > "Field definitions" > "Edit" of a sender column
Prerequisite: the template's "Carrier" (type) is not "Not specified" (otherwise the button does not appear)
Steps:
1. In A "Default value", enter your own information (sender name, address, phone number, etc.)
2. In B "Branches — exceptions", press "Add from template". A card opens
3. Choose "Billing value to use" (Name / Phone / Postal code / Address / Address 2). If the column name is still the preset one such as "ご依頼主名", it is already selected. For a renamed column, choose it yourself
4. Press "Add". One branch is added (when "Billing address matches shipping address" contains "false", the billing value is output)
5. Repeat per column, then "Save" and "Save" in the CSV screen's save bar
Notes:
- Orders whose billing and shipping addresses are the same keep the A default value. If the billing address lacks the item, the cell is left empty
- The added branch is an ordinary conditional branch. The combination of values and character conversion can be changed with "Edit" in the list
- A column that already has the gift branch shows "Added" and cannot get a second one

PROC-V5 Output the delivery date and delivery time

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template > "Field definitions" > "Edit" of the target column
Steps:
1. "Edit" of the column → A "Detail" → choose "Delivery Date (App)" in order information ("Delivery Time (App)" for time)
2. Specify the date format ("Date format": YYYY-MM-DD, etc.)
3. Save
Note: for orders with no delivery date and time (for example dynamic checkout) the cell is empty.
     To fill in the delivery date and time afterwards for an order, there is a way using metafields (PROC-V8)

PROC-V6 Build a value with code (JavaScript)

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template > "Field definitions" > "Edit" of the target column
Steps: "Edit" of the column → A "Detail" → set the line type to "Code (JavaScript)" and write JavaScript.
      "Edit code with debugger" lets you check the run result against a sample order
How to write:
- Refer to the order information with the order object. The code is an "expression", and the result of that expression is the output value (example: `order.shippingAddress.formattedArea`)
- A single-line expression can be written as is. Code spanning multiple lines (for example, using `const`) must be written as an immediately-invoked function `(() => { ... return value; })()`; without it the correct value is not output
- For date calculation, `dateCalculate(date, days, "YYYY/MM/DD")` can be used. Example: `dateCalculate(order.date, -5, "YYYY/MM/DD")` (5 days before the delivery date), `dateCalculate(new Date(), 5, "YYYY/MM/DD")` (5 days from today). The format is the day.js format
- The result of `dateCalculate(order.date, …)` depends on what the order has as its desired delivery date. For an order whose desired delivery date is a date, the date calculated from it is output. For an order whose value is a string such as "No Request" ("指定しない" / "指定なし"), it cannot be read as a date, so an empty string (blank) is output. For an order with no desired delivery date at all (no value), the date **calculated from today's date** is output; it does not become blank. To give such orders a different value, add a branch in the conditional branches of B (PROC-V4) with the target field "Delivery Date (App)" and an empty value. If the code causes an error, an empty string is output.
- Use const / let for variable declarations (do not use var)
- On an error the cell is empty (the export does not stop). The error details are output to the console of a browser such as Google Chrome. On the screen, the result can be checked in "Preview — output value" on the right of the value edit screen
- List of the order variables you can refer to (what is inside order): [List of order variables (Japanese)](/cc-delivery-date-time/csv-variables)
- day.js is used for date calculation and formatting. Date format notation: https://day.js.org/docs/en/parse/string-format (day.js itself: https://day.js.org/en/)
- `dateCalculate` is defined as follows. A value that cannot be read as a date gives an empty string, the format defaults to `YYYY-MM-DD`, and a negative number goes into the past:
    const dateCalculate = (dateStr, num, format) => {
      const d = dayjs(dateStr);
      if (!d.isValid()) return "";
      return d.add(num, "day").format(format || "YYYY-MM-DD");
    };
- A verification environment where you can try code with variables (external): https://playcode.io/1921690
- A multi-line example (output the number of payment methods):
    (() => {
      const names = order.paymentGatewayNames || [];
      return names.length;
    })()
- This is a feature for people with programming knowledge. When complex code is needed, guide the customer to contact the developer (it may be quoted as a separate fee)
Caution (pitfalls in behavior):
- If the string "customAttribute" is written as it is in the code, the code is not executed and a string joining all the items of "Additional details" is output.
  Workaround: split the string. Example: const ATTR = "custom" + "Attributes"; const attrs = Array.isArray(order[ATTR]) ? order[ATTR] : [];
- For an order that does not have the metafield, order.metafields itself is undefined. Refer to it with ?. as in order.metafields?.['namespace.key'].
  (Plain access throws an exception and that row becomes empty)

PROC-V6a Code samples (paste them as they are into a column’s code field)

Where: same as PROC-V6 ("Edit" of the column → A "Detail" → line type "Code (JavaScript)")
All of them are expressions that can use order and dateCalculate. Those spanning several lines are written as an immediately-invoked function (() => { ... })().

S1 Calculate the shipping date from the desired delivery date (for perishable food, etc.; 5 days before):

dateCalculate(order.date, -5, "YYYY/MM/DD")
  • When the shipping date differs by delivery area, set the default value of A to dateCalculate(order.date, -3, "YYYY/MM/DD"), and in the conditional branches of B (PROC-V4) set the value of “IF the shipping address contains ‘沖縄県’ (Okinawa)” and “IF the product name contains ‘北海道’ (Hokkaido)” to dateCalculate(order.date, -5, "YYYY/MM/DD") (the example in the former manual)

S2 When the desired delivery date is “No Request”, set the earliest estimated delivery date for each delivery area. Set the output of the branch “IF Delivery Date (App) contains ‘No Request’” to code (JavaScript) (a complex condition, so an immediately-invoked function; adjust the areas and days to the store):

(() => {
  const address = order.shippingAddress.formattedArea;
  const format = 'YYYY/MM/DD';
  if (address.includes('北海道')) {
    return dateCalculate(new Date(), 4, format);
  } else if (address.includes('青森県')) {
    return dateCalculate(new Date(), 3, format);
  } else if (address.includes('沖縄県')) {
    return dateCalculate(new Date(), 5, format);
  } else if (
    address.includes('福岡県') ||
    address.includes('佐賀県') ||
    address.includes('長崎県') ||
    address.includes('熊本県') ||
    address.includes('大分県') ||
    address.includes('宮崎県')
  ) {
    return dateCalculate(new Date(), 3, format);
  } else {
    return dateCalculate(new Date(), 2, format);
  }
})()

S3 Output the purchased product names to “Item name 1” and “Item name 2” (the 1st and 2nd products; empty if there is none):

// 1st product (column "Item name 1")
order.lineItems[0]?.title
// 2nd product (column "Item name 2")
order.lineItems[1]?.title

S4 Output the total amount minus the shipping fee:

order.currentTotalPriceSet.shopMoney.amount - order.totalShippingPriceSet.shopMoney.amount

S5 Convert the recipient’s phone number into a string with hyphens (to prevent garbled text in Excel). +81 is changed to 0, then mobile numbers (070/080/090) are split 3-4-4 and other 10-11 digit numbers starting with 0 are split 4-2-4. If neither applies, it is output as it is:

(() => {
  const tel = order.shippingAddress.phone?.replace("+81", "0");
  if (/^0[789]0\d{8}$/.test(tel)) {
    return tel.replace(/(\d{3})(\d{4})(\d{4})/, "$1-$2-$3");
  } else if (/^0\d{9,10}$/.test(tel)) {
    return tel.replace(/(\d{4})(\d{2})(\d{4})/, "$1-$2-$3");
  } else {
    return tel;
  }
})()

S6 Convert the sender’s phone number into a string with hyphens (the billing version of S5. An example where code is set as the output of the branch “IF the shipping address and billing address are the same contains ‘false’”; the sender’s code column):

(() => {
  const tel = order.billingAddress.phone?.replace("+81", "0");
  if (/^0[789]0\d{8}$/.test(tel)) {
    return tel.replace(/(\d{3})(\d{4})(\d{4})/, "$1-$2-$3");
  } else if (/^0\d{9,10}$/.test(tel)) {
    return tel.replace(/(\d{4})(\d{2})(\d{4})/, "$1-$2-$3");
  } else {
    return tel;
  }
})()

S7 Extract only the prefecture from the address (if any of the 47 prefectures is contained in the address, that name is output; an empty string if none is found):

(() => {
  const address = order.shippingAddress.formattedArea;
  const prefectures = [
    "北海道", "青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県",
    "茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県",
    "新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県",
    "静岡県", "愛知県", "三重県", "滋賀県", "京都府", "大阪府", "兵庫県",
    "奈良県", "和歌山県", "鳥取県", "島根県", "岡山県", "広島県", "山口県",
    "徳島県", "香川県", "愛媛県", "高知県", "福岡県", "佐賀県", "長崎県",
    "熊本県", "大分県", "宮崎県", "鹿児島県", "沖縄県"
  ];
  const prefecturePattern = new RegExp(prefectures.join('|'));
  const match = address.match(prefecturePattern);
  return match ? match[0] : "";
})()

S8 Output the total quantity of the whole order (for 2 of product A and 2 of product B, output 4):

(() => {
  return order.lineItems.reduce((a, b) => {
    return a + b.currentQuantity;
  }, 0);
})()

S9 Output the billing phone number if there is one, and the shipping phone number if not (+81 becomes 0):

(() => {
  if (order.billingAddress.phone) {
    return order.billingAddress.phone.replace("+81", "0");
  }
  return order.shippingAddress.phone?.replace("+81", "0");
})()

S10 For a gift order only, you want the “sender” to be the billing information, but even if “the shipping address and billing address are the same” is false, the shipping and billing customer may in fact be the same person. So when both “the postal code of the shipping and billing address” and “the last name of the shipping and billing address” match, it is judged not to be a gift and the default value is output. The example is for Yamato B2 (the column numbers are those of the Yamato B2 preset; change defaults such as "080-0000-9999" to the store’s values). For the whole picture of gift orders see Gift orders: change the sender output when billing and shipping addresses differ (Japanese) and PROC-V4a / PROC-V4b:

// 20 Sender's phone number
(() => {
  if (order.shippingAddress.zip === order.billingAddress.zip && order.shippingAddress.lastName === order.billingAddress.lastName) {
    return "080-0000-9999";
  }
  if (order.billingAddress.phone) {
    return order.billingAddress.phone.replace("+81", "0");
  }
  return "080-0000-9999";
})()
// 22 Sender's postal code
(() => {
  if (order.shippingAddress.zip === order.billingAddress.zip && order.shippingAddress.lastName === order.billingAddress.lastName) {
    return "889-0000";
  }
  return order.billingAddress.zip;
})()
// 23 Sender's address
(() => {
  if (order.shippingAddress.zip === order.billingAddress.zip && order.shippingAddress.lastName === order.billingAddress.lastName) {
    return "Default address";
  }
  return `${order.billingAddress.formattedArea.replace("日本:", "")}${order.billingAddress.address1}`;
})()
// 24 Sender's apartment / building
(() => {
  if (order.shippingAddress.zip === order.billingAddress.zip && order.shippingAddress.lastName === order.billingAddress.lastName) {
    return "Default apartment";
  }
  return order.billingAddress.address2;
})()
// 25 Sender's name
(() => {
  if (order.shippingAddress.zip === order.billingAddress.zip && order.shippingAddress.lastName === order.billingAddress.lastName) {
    return "Default name";
  }
  return `${order.billingAddress.lastName}${order.billingAddress.firstName}`;
})()

PROC-V7 Output the line item property of a product

Where: App left menu "Order List" (or Home > "Order List (CSV)" > "CSV export") > top tab "Settings" > "CSV templates" > "Edit" of the target template
Steps:
1. Under "Split settings for this template", choose "Split every row" (when an order has several products, each product is output on its own row. See the split page: /en/cc-delivery-date-time/ai/120/routing-and-shipping-lead/#split-row-with-product)
2. In "Field definitions", open "Edit" of the column where you want the line item property
3. In B "Branches — exceptions", press "Add branch" → for the target field choose "Products Line Property" (the item name shown in the English admin), and as the value enter the Key (label, title) of the line item property (example: "のし", the gift-wrap label)
4. Set the value to output to "Matched value (value of the tested field)", then "Save branch" → Save → "Save" in the CSV screen's save bar
5. After changing the split setting, fetch again with "Fetch orders" (the row split is not reflected in the order list until you fetch again)
Notes:
- Unless "Split every row" is chosen, the line item property of each product is not output row by row (a line item property is per-product information)
- Outputting a value of the order's "Additional details" (attributes of the whole order) is a different mechanism (order info "Attribute: Key name")

PROC-V8 Output an order metafield / fill a missing delivery date with a metafield

Where: App left menu "Order List" > top tab "Settings" > "Fetch settings" > "Fetch metafields"
Steps (output a metafield):
1. Check "Fetch order metafields" and register the metafield as "namespace.key" (several can be registered)
2. After changing it, fetch the orders again with "Fetch orders"
3. "CSV templates" → "Edit" of the target template → "Field definitions" → "Edit" of the target column → A "Detail": choose "Metafield[namespace.key]" in an order-info line
   (a metafield that is not registered is not fetched, so it does not appear in the options)
4. To change the output depending on the metafield value, "Metafield[namespace.key]" can also be chosen as the target field of a branch in B "Branches — exceptions"
Setting example: output the metafield value when the order has no delivery date
  Background: an order created manually, or one that came in with "Delivery Date is Inactive" (the setting that does not show the date input; the former manual calls it "display delivery date and time"), has no desired-delivery-date property in the order's "Additional details".
              When the customer asks for a delivery date after the order is created, managing it with a metafield is recommended
  1. In Shopify, define order metafields that record the desired delivery date and time (the definition screen differs by store, so check the actual screen when guiding)
  2. Register those metafields in "Fetch settings" and fetch again, as in the steps above
  3. Edit the delivery date column → in B "Branches — exceptions" add a branch with the target field "Delivery Date (App)" and an empty value (V-10), set the value to output to "Metafield[namespace.key]", and "Save branch".
     Do the same for the delivery time column (target field "Delivery Time (App)")
  4. Edit the order's metafield from the order screen in the Shopify admin to enter the value
Notes:
- If the order has a delivery date, the value of A (the delivery date and time that the app wrote) is output. Only orders without one get the metafield value. If the metafield has no value either, the cell is empty
- When you refer to it in code, order.metafields itself is undefined for an order without that value, so write order.metafields?.['namespace.key'] (PROC-V6)
- For the setting that hides the delivery date, point to the blog article (Japanese only) [Hide the delivery date with CC Delivery Date & Time](/blogs/non-display)

QA

  • Q: I want to split the postal code into the first 3 and last 4 digits. A: Split the “postal code” into two columns and set the replacement rules with regular expressions. For the example see PROC-V3a (first 3 digits -...., last 4 digits ...-).
  • Q: I want “+81” in a phone number to be “0”. A: PROC-V3.
  • Q: I want the prefecture and the city in separate columns. A: Output the prefecture with a conditional branch (B) per prefecture. For the city, remove the leading prefecture with a regular expression in a replacement rule (replace ^(.{2}[都道府県]|.{3}県) with empty; PROC-V3a).
  • Q: I want to switch the carrier or a value by condition. A: Switching a value is the conditional branch of B (PROC-V4). Switching the template itself is done with “Routing rules” (another page).
  • Q: For gift orders I want the sender to be the billing address. A: PROC-V4a for all columns at once (“Make the sender gift-ready” in Basic info), or PROC-V4b per column. Use “Add from template” in B and add the billing value to use. The steps are also in “Gift orders: change the sender output when billing and shipping addresses differ” (/blogs/csv-gift/, Japanese only). For a code-based judgment see S10 in PROC-V6a.
  • Q: I want to output with a formula, such as a total calculation. A: Calculate it with code (JavaScript) (PROC-V6). To treat a missing value as 0, attach a replacement rule with “before” empty and “after” set to 0 to that order-info line (note in PROC-V3). For code examples see PROC-V6a (S4, S8).
  • Q: I want to output a metafield value. A: PROC-V8. Register the metafield key in “Fetch settings”, fetch again, then choose the key under “metafield” in order information. An order that does not have it gives an empty cell (caution in PROC-V6).
  • Q: The delivery date does not appear in the CSV for orders created manually. A: Because the order has no delivery-date property. Put the delivery date learned after the order into a metafield, and make a branch that outputs the metafield only when the delivery date is empty (the setting example in PROC-V8).
  • Q: I want to calculate a date, such as 5 days before the delivery date. A: With code, dateCalculate(order.date, -5, "YYYY/MM/DD") (PROC-V6). Note that an order with no delivery date is calculated from today’s date.
  • Q: I want the phone number with hyphens (garbled in Excel). A: S5 (recipient) and S6 (sender) in PROC-V6a.
  • Q: I want the total quantity of the whole order. A: S8 in PROC-V6a.
  • Q: The code does not work and a long string of attributes is output. A: Check whether the code contains the string “customAttribute” (the pitfall in PROC-V6).
  • Q: I want to output the line item properties of a product. A: PROC-V7. Line item properties are per-product information, so choose “Split every row”, then specify the Key in the target field “Products Line Property” and set the output to “Matched value” (PROC-V7). If it does not appear, see ESCALATE.

ESCALATE

SituationInformation to request
A column’s value is not as expected / is emptyTemplate name, column name, the expected value, the target order number, a screenshot of that column’s settings (A, B, C)
A regular expression / code does not workThe code or regular expression itself, the actual value of the item in the target order, the error shown. A complex regular expression or code is an individual design and may be quoted as a separate fee
Line item properties / metafields do not appearThe key name set, a screenshot of the order’s “Additional details” / metafield, the “Fetch settings” screen
Want to match a carrier’s specified formatCarrier name, specification of the import format (number of columns, column order, required fields, encoding). It is an individual design, so draft an inquiry to the developer

SEE

Install