Skip to content

Conversation

@vhudlikar
Copy link
Contributor

This is a Action that handles the tag creation part of the feature. #6

Inputs needed for this action.

Input Label Name (Internal) Type Description Required
Primary Table primary_table String The name of the main table (e.g., incident). Yes
Primary Table Query primary_table_query String The encoded query for the primary table (e.g., active=true^priority=1). Yes
Primary Fields primary_fields String Comma-separated list of fields to retrieve from the primary table (e.g., number,short_description). Yes
Primary Join Field primary_join_field String The field on the Primary Table that holds the relationship (e.g., caller_id). Yes
Joined Table joined_table String The name of the table to join (e.g., sys_user). Yes
Joined Join Field joined_join_field String The field on the Joined Table that matches the Primary Join Field (e.g., sys_id). Yes
Joined Table Fields joined_table_fields String Comma-separated list of fields to retrieve from the joined table (e.g., name,email). Yes
Joined Table Query joined_table_query String Optional encoded query to filter the joined table data (e.g., active=true). No

Logic

  1. Validate All Inputs (Pre-Check): Before touching the database, the action rigorously checks all mandatory inputs. It confirms that the Primary Table, Joined Table, Primary Join Field, and Joined Join Field inputs are all valid, existing tables and fields in the system dictionary. If any are misspelled, the action immediately stops and signals FAILURE.
  2. Find Primary Records & Collect Keys: The action executes the user's primary encoded query (e.g., active=true) against the Primary Table (incident). While processing these records, it extracts the value of the Primary Join Field (caller_id) and stores only the unique keys in an optimized list (like a shopping list for people to look up).
  3. Perform Efficient Joined Lookup: The unique key list is used to construct a single, highly efficient IN query (e.g., sys_id IN (key1, key2, key3...)) against the Joined Table (sys_user). This fetches all necessary related records and their fields (name, email) in a single server call.
  4. Merge Data & Format Output: The script matches the original primary records with the data retrieved in the lookup (Step 3) using the join key. It then merges the requested fields from both tables into a single, comprehensive record object.
  5. Deliver Results & Status: The final, merged array of records is converted into a JSON text string for flexible use by the consuming flow. It also reports the final Action Status (SUCCESS or FAILURE) and the counts of primary and joined records found, providing full transparency.

Output

  • This Action provides a complete transactional report: It delivers the core Joined Records Data (as a JSON String ready for the JSON Parser) alongside its final Action Status and any detailed Error Message if validation failed. For complete transparency, it also includes metrics showing the Total Primary Records Found at the start and the Total Joined Records Returned after the final merge.

Testing Result:
Before running action below was filter data I took.
image

Below is input given to action:
image

And now final output in JSON string format
image

[ { "number": "INC0010003", "short_description": "Antivirus not working", "name": "Abraham Lincoln", "email": "abraham.lincoln@example.com" }, { "number": "INC0010010", "short_description": "P1 ticket", "name": "Abraham Lincoln", "email": "abraham.lincoln@example.com" }, { "number": "INC0000054", "short_description": "SAP Materials Management is slow or there is an outage", "name": "Christen Mitchell", "email": "christen.mitchell@example.com" }, { "number": "INC0010004", "short_description": "test ticket 2", "name": "Abraham Lincoln", "email": "abraham.lincoln@example.com" }, { "number": "INC0010005", "short_description": "test ticket 1", "name": "Abraham Lincoln", "email": "abraham.lincoln@example.com" }, { "number": "INC0007001", "short_description": "Employee payroll application server is down.", "name": "David Miller", "email": "david.miller@example.com" } ]

Fail UseCase:
We are providing intentionally wrong field for join which is caller_d instead of caller_id.
image

Result
Failure with error message.
image

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

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!

@ravichandra1998g ravichandra1998g self-assigned this Oct 6, 2025
Copy link
Contributor

@ravichandra1998g ravichandra1998g left a comment

Choose a reason for hiding this comment

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

Thank you for submitting, looks good!

@ravichandra1998g ravichandra1998g merged commit ccdbdcb into ServiceNowDevProgram:main Oct 6, 2025
2 checks passed
@vhudlikar vhudlikar deleted the 06Oct2025Branch1 branch October 7, 2025 08:43
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.

2 participants