Skip to content

Conversation

chetnadev
Copy link
Contributor

The script enhances a form field (specifically the description field) by: -Adding a live word counter below the field. -Visually warning the user if the word count exceeds 150 words.

This client-side script, intended for use in a ServiceNow form (e.g., catalog item or incident form), dynamically appends a custom

element below the description field to display a real-time word count. It leverages the g_form.getControl() API to access the field's DOM element and attaches an input event listener to monitor user input. The script calculates the word count by splitting the input text using a regular expression (\s+) and updates the counter accordingly. It applies conditional styling to the counter (green if ≤150 words, red if >150), providing immediate visual feedback to the user to enforce input constraints.

@SapphicFire SapphicFire self-assigned this Oct 12, 2025
Copy link
Contributor

@SapphicFire SapphicFire 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 your contribution. As mentioned in the file comment, I cannot currently approve this as DOM manipulation is not something we encourage and is not in line with best practice. I have suggested an alternate method if you would like to implement this, though it may work best with an onChange script.

Copy link
Contributor

@SapphicFire SapphicFire 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 to me, thank you

@SapphicFire SapphicFire merged commit 8e89998 into ServiceNowDevProgram:main Oct 12, 2025
1 check passed
@chetnadev
Copy link
Contributor Author

Thankyou @SapphicFire for the suggestions :)

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