Skip to content

[21377] feat(servicenow): expand knowledge base retrieval in search-knowledge-base#21391

Open
ashwins01 wants to merge 2 commits into
masterfrom
issue-21377-servicenow
Open

[21377] feat(servicenow): expand knowledge base retrieval in search-knowledge-base#21391
ashwins01 wants to merge 2 commits into
masterfrom
issue-21377-servicenow

Conversation

@ashwins01

@ashwins01 ashwins01 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #21377

  • Search Knowledge Base (0.0.1 -> 0.1.0): new optional Knowledge Base IDs prop, mapping to the documented kb query param.
  • Get Article (new): returns the entire HTML content. Accepts a sys_id or a KB number, per the docs.
  • Get Article Attachment (new): downloads to /tmp and returns the path.
  • List Knowledge Bases (new): reads kb_knowledge_base so users can find the sys_ids that scope a search..
  • Bug fix: fields on Search Knowledge Base was serialized as repeated query params (paramsSerializer: { indexes: null }). The API documents fields as a comma-separated string, and its response meta echoes back "fields": "short_description" for the comma form. Changed to .join(",").
  • Bug fix: _makeRequest returns response.result, which is undefined for the attachment endpoint (it returns a file, not a { result } envelope). Split out _makeRawRequest; _makeRequest now delegates to it. No behavior change for existing callers.

Checklist

Please check the following items before your PR can be reviewed:

Versioning

  • All components updated in this PR had their version updated (0.0.1 for new ones)
  • The app updated in this PR had its package.json's version updated

New app

If this is a new app, please submit an app integration request - the PR will only be reviewed after the app is integrated.

  • The app updated in this PR is already integrated

CodeRabbit review

After the PR is opened, and if new changes are pushed, CodeRabbit will automatically review it. Do not 'mark as resolved' CodeRabbit's comments, but reply to them instead, whether you agree (and update the PR accordingly) or disagree.

  • I have addressed or acknowledged all of CodeRabbit's review comments

Summary by CodeRabbit

  • New Features
    • Added actions to retrieve knowledge articles and download article attachments.
    • Added an action to list knowledge bases.
  • Enhancements
    • Knowledge-base searches can now be limited to specific knowledge base IDs.
    • Improved consistency in search and article response handling.
  • Release Updates
    • Refreshed ServiceNow action versions across cart, catalog, record, user, and knowledge-base capabilities.
    • Updated the ServiceNow integration package version.

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pipedream-docs-redirect-do-not-edit Ignored Ignored Jul 15, 2026 3:45pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds ServiceNow actions and app methods for retrieving knowledge articles, attachments, and knowledge bases. Knowledge-base search gains filtering and updated response handling. Existing action versions and the ServiceNow package version are incremented.

Changes

ServiceNow knowledge capabilities

Layer / File(s) Summary
Knowledge request foundation
components/servicenow/common/constants.mjs, components/servicenow/servicenow.app.mjs
Adds the knowledge-base table constant, shared fields input, raw request helper, and knowledge article, attachment, and knowledge-base API methods.
Article and knowledge-base actions
components/servicenow/actions/get-article/*, components/servicenow/actions/get-article-attachment/*, components/servicenow/actions/list-knowledge-bases/*
Adds actions for retrieving articles, downloading attachments to /tmp, and listing knowledge bases.
Knowledge search expansion
components/servicenow/actions/search-knowledge-base/*
Adds optional knowledge-base filtering, comma-separated request fields, updated descriptions, and response extraction from response.articles.
Action and package metadata
components/servicenow/actions/*, components/servicenow/package.json
Increments existing action versions and updates the package version from 0.11.0 to 0.12.0.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Action
  participant ServiceNowApp
  participant ServiceNowAPI
  participant FileSystem
  Action->>ServiceNowApp: getKnowledgeArticle(articleId, fields)
  ServiceNowApp->>ServiceNowAPI: Fetch article
  ServiceNowAPI-->>ServiceNowApp: Article response
  ServiceNowApp-->>Action: Return article
  Action->>ServiceNowApp: getKnowledgeArticleAttachment(articleSysId, attachmentSysId)
  ServiceNowApp->>ServiceNowAPI: Fetch attachment as arraybuffer
  ServiceNowAPI-->>ServiceNowApp: Attachment content
  ServiceNowApp-->>Action: Return attachment content
  Action->>FileSystem: Write attachment under /tmp
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Most requested KB features are implemented, but the plugin-activation error handling called out in #21377 isn't shown. Add error handling or docs that surface the sn_km_api plugin requirement when the Knowledge API is unavailable.
Out of Scope Changes check ⚠️ Warning Several unrelated ServiceNow actions only received version bumps, which don't map to the knowledge-base retrieval objective. Move unrelated version-only bumps for cart/order/table actions into a separate release PR, or explain why they must ship with this feature.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: expanding ServiceNow knowledge base retrieval in the search-knowledge-base action.
Description check ✅ Passed The description follows the template with a Summary and Checklist, and it documents the main changes and versioning status.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-21377-servicenow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/servicenow/actions/get-article-attachment/get-article-attachment.mjs`:
- Around line 47-48: Update the file path construction near the writeFile call
to sanitize this.fileName with path.basename before joining it with /tmp, while
retaining attachmentSysId as the fallback when no file name is provided. Ensure
the resulting path always remains directly inside /tmp.

In `@components/servicenow/actions/get-article/get-article.mjs`:
- Around line 21-26: Centralize the shared fields prop in servicenow.app.mjs
under propDefinitions, preserving its current type, label, description, and
optional behavior. In
components/servicenow/actions/get-article/get-article.mjs:21-26 and
components/servicenow/actions/search-knowledge-base/search-knowledge-base.mjs:36,
remove the inline definitions and reference the shared prop with propDefinition:
[servicenow, "fields"].
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cb005987-23c6-4e58-a0d4-5105c5e7fb74

📥 Commits

Reviewing files that changed from the base of the PR and between 1c60ed0 and e02e797.

📒 Files selected for processing (28)
  • components/servicenow/actions/add-item-to-cart/add-item-to-cart.mjs
  • components/servicenow/actions/check-order-status/check-order-status.mjs
  • components/servicenow/actions/checkout-cart/checkout-cart.mjs
  • components/servicenow/actions/create-table-record/create-table-record.mjs
  • components/servicenow/actions/delete-cart-item/delete-cart-item.mjs
  • components/servicenow/actions/delete-table-record/delete-table-record.mjs
  • components/servicenow/actions/empty-cart/empty-cart.mjs
  • components/servicenow/actions/find-users/find-users.mjs
  • components/servicenow/actions/get-article-attachment/get-article-attachment.mjs
  • components/servicenow/actions/get-article/get-article.mjs
  • components/servicenow/actions/get-catalog-item-variables/get-catalog-item-variables.mjs
  • components/servicenow/actions/get-current-user/get-current-user.mjs
  • components/servicenow/actions/get-record-counts-by-field/get-record-counts-by-field.mjs
  • components/servicenow/actions/get-table-record-by-id/get-table-record-by-id.mjs
  • components/servicenow/actions/get-table-records/get-table-records.mjs
  • components/servicenow/actions/list-knowledge-bases/list-knowledge-bases.mjs
  • components/servicenow/actions/list-tables/list-tables.mjs
  • components/servicenow/actions/order-catalog-item/order-catalog-item.mjs
  • components/servicenow/actions/search-catalog-items/search-catalog-items.mjs
  • components/servicenow/actions/search-knowledge-base/search-knowledge-base.mjs
  • components/servicenow/actions/search-records-by-keyword/search-records-by-keyword.mjs
  • components/servicenow/actions/submit-cart-order/submit-cart-order.mjs
  • components/servicenow/actions/submit-record-producer/submit-record-producer.mjs
  • components/servicenow/actions/update-table-record/update-table-record.mjs
  • components/servicenow/actions/view-cart/view-cart.mjs
  • components/servicenow/common/constants.mjs
  • components/servicenow/package.json
  • components/servicenow/servicenow.app.mjs

Comment thread components/servicenow/actions/get-article-attachment/get-article-attachment.mjs Outdated
Comment on lines +21 to +26
fields: {
type: "string[]",
label: "Fields",
description: "Additional `kb_knowledge` fields to return under `fields`. Example: `short_description`, `sys_class_name`.",
optional: true,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Centralize the duplicated fields prop in the app file.

The fields prop is defined inline in multiple components, duplicating its definition and configuration. As per coding guidelines and path instructions, any prop used by more than one component must be defined in the app file's propDefinitions and referenced via propDefinition.

Move the fields prop configuration into servicenow.app.mjs and update these components to reference it:

  • components/servicenow/actions/get-article/get-article.mjs#L21-L26: Replace the inline definition with propDefinition: [servicenow, "fields"].
  • components/servicenow/actions/search-knowledge-base/search-knowledge-base.mjs#L36-L36: Replace the inline fields prop definition with the same propDefinition reference.

As per learnings, relocating a prop from an inline definition to a shared propDefinition does not warrant a major version bump provided the prop key and behavior remain intact.

📍 Affects 2 files
  • components/servicenow/actions/get-article/get-article.mjs#L21-L26 (this comment)
  • components/servicenow/actions/search-knowledge-base/search-knowledge-base.mjs#L36-L36
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/servicenow/actions/get-article/get-article.mjs` around lines 21 -
26, Centralize the shared fields prop in servicenow.app.mjs under
propDefinitions, preserving its current type, label, description, and optional
behavior. In components/servicenow/actions/get-article/get-article.mjs:21-26 and
components/servicenow/actions/search-knowledge-base/search-knowledge-base.mjs:36,
remove the inline definitions and reference the shared prop with propDefinition:
[servicenow, "fields"].

Sources: Coding guidelines, Path instructions, Learnings

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/servicenow/actions/get-article-attachment/get-article-attachment.mjs`:
- Around line 47-48: Update the filename selection before the writeFile call to
reject basename results of "..", ".", or an empty string, falling back to
attachmentSysId for those values. Preserve the existing path.basename behavior
for safe filenames and continue using the resulting name with path.join("/tmp",
...) in the attachment action.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2843a474-7e66-47b4-929f-f99eca810334

📥 Commits

Reviewing files that changed from the base of the PR and between e02e797 and 0e5718a.

📒 Files selected for processing (4)
  • components/servicenow/actions/get-article-attachment/get-article-attachment.mjs
  • components/servicenow/actions/get-article/get-article.mjs
  • components/servicenow/actions/search-knowledge-base/search-knowledge-base.mjs
  • components/servicenow/servicenow.app.mjs

Comment on lines +47 to +48
const filePath = path.join("/tmp", path.basename(this.fileName || this.attachmentSysId));
await fs.promises.writeFile(filePath, content);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
node - <<'NODE'
import path from "node:path";

for (const name of ["..", ".", "/", "../../file.pdf"]) {
  console.log(name, "=>", path.join("/tmp", path.basename(name)));
}
NODE

Repository: PipedreamHQ/pipedream

Length of output: 219


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,220p' components/servicenow/actions/get-article-attachment/get-article-attachment.mjs | cat -n

Repository: PipedreamHQ/pipedream

Length of output: 2584


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the action file and related attachment methods/props.
rg -n "fileName|attachmentSysId|writeFile|path.join\(\"/tmp\"" components/servicenow -g '*.mjs'

# Show the target file with line numbers.
sed -n '1,220p' components/servicenow/actions/get-article-attachment/get-article-attachment.mjs | cat -n

Repository: PipedreamHQ/pipedream

Length of output: 3437


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "fileName|attachmentSysId|writeFile|path.join\\(\"/tmp\"" components/servicenow -g '*.mjs'

echo "----"
sed -n '1,220p' components/servicenow/actions/get-article-attachment/get-article-attachment.mjs | cat -n

Repository: PipedreamHQ/pipedream

Length of output: 3442


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target file =="
sed -n '1,220p' components/servicenow/actions/get-article-attachment/get-article-attachment.mjs | cat -n

echo "== related references =="
rg -n "fileName|attachmentSysId|get-article-attachment|Get Article Attachment" components/servicenow -g '*.mjs'

Repository: PipedreamHQ/pipedream

Length of output: 3587


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== similar tmp write patterns =="
rg -n 'path\.join\("/tmp"|writeFile\(filePath|basename\(this\.' components/servicenow -g '*.mjs'

echo "== target action outline =="
ast-grep outline components/servicenow/actions/get-article-attachment/get-article-attachment.mjs --view expanded

Repository: PipedreamHQ/pipedream

Length of output: 626


🏁 Script executed:

#!/bin/bash
set -euo pipefail

nl -ba components/servicenow/actions/get-article-attachment/get-article-attachment.mjs | sed -n '1,220p'

Repository: PipedreamHQ/pipedream

Length of output: 199


Guard against unsafe attachment filenames. path.basename() can still return .., ., or "", which makes path.join("/tmp", ...) target / or /tmp and fail on write; fall back to attachmentSysId for those cases.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/servicenow/actions/get-article-attachment/get-article-attachment.mjs`
around lines 47 - 48, Update the filename selection before the writeFile call to
reject basename results of "..", ".", or an empty string, falling back to
attachmentSysId for those values. Preserve the existing path.basename behavior
for safe filenames and continue using the resulting name with path.join("/tmp",
...) in the attachment action.

@michelle0927 michelle0927 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Ready for QA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ACTION] ServiceNow: expand knowledge base retrieval in search-knowledge-base action

2 participants