Skip to content

Conversation

@anurampalli
Copy link
Contributor

Two-Step Flow Designer Action: JSON Parsing and Email Notification

This is a design document for a reusable, two-step Flow Designer Action for parsing a JSON payload and sending its contents in a well-formatted email (Text or HTML).


1. Action Name & Description

Field Value
Action Name JSON Parser & Email Sender
Description Recursively parses JSON data and sends a formatted email (Text or HTML) to specified recipients. Ideal for incident notifications.
Use Case Automatically alert support teams and management of high-priority incidents, including all relevant fields, in a well-formatted email.

2. Step 1: Script - JSON Parser

This step contains the core logic for recursive JSON parsing and formatting.

2.1 Inputs

Input Name Type Description Required
jsonString String The raw JSON string to be parsed (e.g., the payload from an inbound integration). Yes
emailSubject String The subject for the outgoing email. Yes
emailTo String Comma or semicolon-separated list of email addresses. Yes
outputFormat String (Choice) text or html. Determines the formatting of the emailBody. Yes

2.2 Script Logic (Pseudo-code/Summary)

  1. Input Validation: Check if jsonString is null or empty. If so, set emailBody to an error message and status to 'Error'.
  2. Parsing Attempt: Attempt to parse jsonString using a built-in JSON parser function (e.g., JSON.parse()).
  3. Error Handling (Invalid JSON):
    • If parsing fails, set status to 'Error'.
    • Set emailBody to a descriptive error message: "Error: Invalid JSON structure provided. Details: [Parsing Error Message]".
  4. Recursive Formatting Function (formatJson(data, format)):
    • Handles Objects: Iterates over key/value pairs. If the value is another object or array, it calls itself recursively.
      • HTML: Formats data into an HTML <table> or ordered/unordered list (<ol>, <ul>).
      • Text: Formats data using clear key-value pairs with indentation and line breaks.
    • Handles Arrays: Iterates over elements. If an element is complex, calls itself recursively.
    • Handles Primitive Types (string, number, boolean): Appends the key and value to the body string, respecting the output format.
  5. Output Generation: Call formatJson(parsedData, outputFormat). Set the returned string to emailBody.
  6. Set status to 'Success'.

2.3 Outputs

Output Name Type Description
emailBody String The fully formatted email content (Text or HTML).
status String 'Success' or 'Error'. Used for conditional logic in Step 2.
emailSubject String Passed through from input.
emailTo String Passed through from input.

3. Step 2: Email - Send Formatted Email

This step is a standard Email action that consumes the outputs from Step 1.

3.1 Inputs

Field Value (Mapped from Step 1) Notes
Target Email $Step 1.emailTo Multiple recipients handled by the system's email action.
Subject $Step 1.emailSubject
Body (HTML/Text) $Step 1.emailBody Crucially, the email action must respect the outputFormat choice.

3.2 Conditional Logic

  • HTML Email: If $Step 1.outputFormat is 'html', ensure the email body is sent as HTML content.
  • Text Email: If $Step 1.outputFormat is 'text', ensure the email body is sent as plain text content.

4. Notable Features & Testing Summary

  • Modular Design: Step 1 (JSON Parser) is self-contained and reusable in other actions requiring JSON to structured text/HTML conversion.
  • outputFormat Choice: Allows the caller to easily switch between simple text (for plain terminals/low-fidelity) and rich HTML (for better readability/branding).
  • Robust Error Handling:
    • The flow does not fail silently on invalid/empty JSON.
    • The error message is captured in the $Step 1.emailBody and sent in the notification, immediately alerting the recipients to the parsing issue (e.g., a bad integration payload).
  • Testing Confirmation:
    • Confirmed formatting correctness for both Text and HTML outputs.
    • Verified email delivery to multiple addresses using comma/semicolon separators in emailTo.

admin added 2 commits October 2, 2025 20:14
…ts by removing a specified number of header lines. The script fetches the target attachment, skips the requested number of lines, and outputs the cleaned CSV content. Optionally, it can write back the cleaned data as a new attachment. Handles missing content and errors gracefully.

Inputs(attachmentSysId, linesToSkip,writeBackAsAttachment, parentTable, parentSysId, newFileName)
Outputs (cleanedCSV, cleanedAttachmentSysId)
…text or HTML.

Use Case:
Automatically alert support teams and management of high-priority incidents, including all relevant fields, in a well-formatted email.

Step 1 – Script:

Recursively parses JSON (jsonString) into text or HTML (tables/lists).

Supports nested objects and arrays.

Outputs emailBody and status.

Step 2 – Email:

Sends the formatted email using emailTo and emailSubject.

Script step is modular and reusable.

Notable Features:

outputFormat choice input added.

Handles empty/invalid JSON gracefully with descriptive error messages in email body.

Testing:

Verified both text and HTML outputs.

Confirmed emails to multiple recipients.

Errors in JSON parsing appear in the email body instead of failing silently.
@github-actions
Copy link

github-actions bot commented Oct 4, 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!

@rohi-v rohi-v self-assigned this Oct 4, 2025
@rohi-v
Copy link
Contributor

rohi-v commented Oct 4, 2025

Thanks for your submission.
It appears that this pull request contains more files than described in the title. Please review and update the pull request to either remove the extra/unintended files or to update the description to be more comprehensive. Ensure your contributions are meaningful and adhere to the project’s standards. [If applicable: You can create a new branch on your forked repository to avoid accidental inclusions of new commits in the future.]. Closing this for now. Once you make additional changes, feel free to re-open this Pull Request or create a new one.

@rohi-v rohi-v closed this Oct 4, 2025
@anurampalli
Copy link
Contributor Author

anurampalli commented Oct 4, 2025 via email

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