Skip to content

Conversation

@VaishnaviLathkar98
Copy link
Contributor

This custom Flow Designer action converts selected fields from any ServiceNow record into a JSON-formatted string. It’s ideal for API integrations, structured logging, or sharing readable record data with other systems or processes.
The action dynamically extracts field values handling reference, choice, and date/time fields and produces clean, human-readable, API-ready JSON output.

Description:
This Flow Designer Script Action takes a record from any ServiceNow table and converts selected fields into a formatted JSON string. It includes robust error handling and proper formatting for different field types, ensuring the output is clean, reliable, and API-ready.

How it works:

Inputs:

  1. tableName (String): Name of the table (e.g., incident)
  2. recordSysId (String): Sys ID of the record to convert
  3. fields (Array of Strings): List of field names to include in the JSON

Logic:

  1. Validates required inputs (tableName, recordSysId, fields)
  2. Returns a clear error message and sets issuccess = false if:
  3. Inputs are missing
  4. Record is not found
  5. Field list is empty

Fetches the record and loops through the selected fields:
Skips excluded fields like work_notes and comments

Handles field types intelligently:

  1. Reference fields → Uses display value
  2. Choice fields → Uses display label
  3. Date/time fields → Formats as ISO string
  4. All others → Uses raw value
  5. Converts the final object into a pretty-printed JSON string

Outputs:

  1. jsonstring: The resulting JSON output or error information
  2. issuccess: true if successful, false if any error occurred
  3. errorMsg: Description of any error (empty if successful)

Notes:

  1. This action excludes work_notes and comments to avoid large or formatted content.
  2. If an invalid sys_id is passed, it will return a clear "Record not found" error.
  3. Built-in error handling prevents flow failure and makes troubleshooting easier.

@github-actions
Copy link

Valid PR for ActionPack

Thank you for your contribution. This PR complies with the CONTRIBUTING.md.
A maintainer will review this shortly. In the meantime, Happy Hacking!

@rohi-v rohi-v self-assigned this Oct 19, 2025
…finition_2ca7fcef47a43210d5daa3c9316d4328.xml
@rohi-v rohi-v removed their assignment Oct 19, 2025
@am-shakeel am-shakeel self-assigned this Oct 19, 2025
Copy link
Contributor

@am-shakeel am-shakeel left a comment

Choose a reason for hiding this comment

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

Looks good

@am-shakeel am-shakeel merged commit ce77000 into ServiceNowDevProgram:main Oct 19, 2025
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.

3 participants