Digital Automation · Focus area 2: Code inside the workflow
DA5: Code inside the workflow
Goal: write short JavaScript and Python steps inside a workflow when ready-made nodes can't do the job: knowing when code is the right choice, reading items in and returning items out, common transformations, and testing code so others can trust it.
You'll need: your n8n set-up, the Sharma Textiles order workflow and the cleaned data from DA4, and the JavaScript you learned in Level 3.
Time: reading about 2 hours · practice (the Try it tasks) about 3 hours · assignment about 3 to 4 hours.
Where this is used: most real workflows have one or two small code steps: grouping orders by customer, building a message from many fields, or checking a value against a rule. Knowing a little code lets an automation builder finish jobs that would otherwise need a developer.
How it differs: an app developer writes whole programs. A code step in a workflow is usually five to forty lines that take items in and hand items on. The skill is keeping it small, readable and tested, so the visual workflow still explains itself.
Lessons
- 1When a ready-made step isn't enoughReading 15–25 minutes, plus practice✓
- 2The Code node in JavaScriptReading 15–25 minutes, plus practice✓
- 3Python in the workflowReading 15–25 minutes, plus practice✓
- 4Common transformationsReading 15–25 minutes, plus practice✓
- 5Testing and keeping code safeReading 15–25 minutes, plus practice✓
🛠️Assignment: Code steps for Sharma Textiles
This adds the code steps used by the weekly CRM tidy-up and the payment workflow projects.
- Find one place in your order workflow where a Code node is clearer than a chain of nodes, and write down why.
- Build the daily owner summary in a JavaScript Code node: order count, revenue in rupees and the top three products.
- Write the order count and total step in Python too, and confirm both versions give the same result.
- Build the CRM deduplication step with a written "which record wins" rule and a before-and-after report.
- Write and run a test table of at least five cases, including an empty input, a missing field and a duplicate.
Self-check before you finish:
- [ ] Every Code node has a clear name and a note saying what it does.
- [ ] Each Code node returns an array of
{ json: ... }items. - [ ] Missing prices or rates stop the run with a clear message instead of becoming zero.
- [ ] No API key or password appears in any code step.
- [ ] Every test case was run and its result recorded.
✅Module check
Explain in a few sentences, in your own words:
When and how should an automation builder use code inside a workflow?
Show a good answer
A good answer mentions: preferring ready-made nodes and expressions when they fit, and using a Code node when logic would
need a long chain of nodes or must look across all items; returning an array of { json } items and choosing "all items" or "each
item" mode; choosing JavaScript or Python by what the platform supports and who maintains it, with heavy work moved to a separate
service; the common patterns of filter, map, group, deduplicate and look up, with a written rule for which record wins; and testing
with pinned awkward cases, failing loudly on bad input, and keeping secrets in credentials.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
