Skip to content

Conversation

@zephyrzilla
Copy link
Member

@zephyrzilla zephyrzilla commented Nov 25, 2025

Summary

This PR introduces a complete ServiceNow integration for SyGra, enabling workflows to read from and write to ServiceNow tables using the PySNC library. The integration includes a full-featured handler with automatic table creation, multiple authentication methods, flexible querying, and comprehensive documentation.

Explain the features implemented:

Data Handler (ServiceNowHandler)

  • Read Operations: Query any ServiceNow table with support for filters, field selection, ordering, pagination, and batch processing
  • Write Operations: Insert new records, update existing records, or upsert (insert or update) based on key field matching
  • Auto-Table Creation: Automatically creates custom ServiceNow tables (prefixed with u_) if they don't exist, including field inference from sample data
  • Automatic Field Prefixing: Adds u_ prefix to field names for custom tables

Authentication & Configuration

  • Multiple Auth Methods:
    • Basic authentication (username/password)
    • OAuth2 password grant flow
    • Environment variable support (SNOW_INSTANCE, SNOW_USERNAME, SNOW_PASSWORD, SNOW_OAUTH_CLIENT_ID, SNOW_OAUTH_CLIENT_SECRET)
  • Flexible Configuration: Full Pydantic model support with DataSourceConfig and OutputConfig

Query Building

  • Dict-based Filters: Simple equality, multiple values (OR logic), complex operators (>=, <=, IN, etc.)
  • Encoded Queries: Native ServiceNow query syntax support
  • Field Selection: Optimize performance by specifying only needed fields
  • Ordering & Pagination: Control sort order and batch sizes

Field Type Inference

Automatically infers ServiceNow field types when creating custom tables:

  • bool → Boolean
  • int → Integer
  • str (≤255 chars) → String (255)
  • str (>255 chars) → String (4000)
  • dict/list → String (4000, JSON-serialized)

Integration API

  • Fluent API: sygra.data.from_servicenow() and sygra.data.to_servicenow()
  • Workflow Integration: Seamless source/sink support in SyGra workflows

How to Test the feature

Prerequisites

# Install PySNC (already in pyproject.toml)
poetry install

# Set environment variables (get PDI from developer.servicenow.com)
export SNOW_INSTANCE="dev000000"
export SNOW_USERNAME="admin"
export SNOW_PASSWORD="your_password"

Test 1: Read from ServiceNow

poetry run python main.py -t examples.servicenow_ai_analysis_insert -n 10

Expected Result: Reads 10 incidents, analyzes with GPT-4o-mini, creates u_ai_incident_analysis table, inserts records

Test 2: Update Existing Records

poetry run python main.py -t examples.servicenow_ai_analysis_update -n 5

Expected Result: Reads 5 records from custom table, generates paraphrases, updates same records

Test 3: Verify Auto-Table Creation

import sygra

sink = sygra.data.to_servicenow(
    instance="dev000000",
    table="u_test_auto_create",  # New table
    operation="insert"
)

workflow = sygra.Workflow("test").source(...).sink(sink)
workflow.run()

Expected Result: Table u_test_auto_create created automatically in ServiceNow

Screenshots (if applicable)

N/A

Checklist

  • Lint fixes and unit testing done
  • End to end task testing
  • Documentation updated

Breaking Changes

None. This is a purely additive feature.

Existing workflows are unaffected. New ServiceNow sources/sinks can be added using:

source = sygra.data.from_servicenow(instance="...", table="...")
sink = sygra.data.to_servicenow(instance="...", table="...", operation="insert")

- Add ServiceNowHandler for reading/writing ServiceNow tables
- Support multiple authentication methods (Basic, OAuth2, env vars)
- Implement auto-table creation for custom tables (u_* prefix)
- Add flexible query building (dict filters, encoded queries)
- Support insert/update/upsert operations with key_field matching
- Add automatic field prefixing for custom tables
- Implement batch processing and streaming mode
- Add comprehensive test suite with mock-based tests
- Add complete documentation in data handler README
- Add example tasks for insert and update workflows
- Add fluent API support (from_servicenow/to_servicenow)
- Update configuration models for ServiceNow sources/sinks
@zephyrzilla zephyrzilla requested a review from a team as a code owner November 25, 2025 14:59
@zephyrzilla zephyrzilla added the enhancement New feature or request label Nov 25, 2025
@zephyrzilla zephyrzilla self-assigned this Nov 25, 2025
@bidyapati-p
Copy link
Collaborator

@psriramsnc @zephyrzilla please resolve the conflict in lambda_node.py

@bidyapati-p
Copy link
Collaborator

Overall code is looking good to merge, except the conflict.

Copy link
Collaborator

@psriramsnc psriramsnc left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@vipul-mittal vipul-mittal merged commit 4667acb into main Dec 2, 2025
2 checks passed
@vipul-mittal vipul-mittal deleted the scratch/servicenow_handler branch December 2, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants