Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.6 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { KnowledgeArticleSchema } from '../common/types';
import { createServiceNowClient, servicenowAuth } from '../common/props';

export const getKnowledgeArticleAction = createAction({
  auth: servicenowAuth,
  name: 'get_knowledge_article',
  classification: 'READ',
  displayName: 'Get Knowledge Article',
  description:
    'Retrieve the full content of a knowledge article by sys_id',
  audience: 'both',
  aiMetadata: {
    description:
      'Fetches the full content of a single knowledge base article by its sys_id; use Search Knowledge Articles first if you only have a KB number. Effectively a read, and idempotent unless the optional Increment View Count flag is enabled, which bumps the article view counter each call. Requires the article sys_id.',
    idempotent: true,
  },
  props: {
    article_sys_id: Property.ShortText({
      displayName: 'Article Sys ID',
      description:
        'sys_id of the article. Use "Search Knowledge Articles" first if you only have a KB number.',
      required: true,
    }),
    update_view: Property.Checkbox({
      displayName: 'Increment View Count',
      description:
        'Whether to increment the article view counter when fetching',
      required: false,
      defaultValue: false,
    }),
  },
  async run(context) {
    const { article_sys_id, update_view } = context.propsValue;
    const client = createServiceNowClient(context.auth);

    const result = await client.getKnowledgeArticle({
      article_sys_id,
      update_view,
    });

    return KnowledgeArticleSchema.parse(result);
  },
});