Skip to content

Adding code snippet to validate user profile #1547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

wendy-ha18
Copy link
Contributor

@wendy-ha18 wendy-ha18 commented Oct 28, 2024

Overview

This JavaScript code snippet is designed to validate user profile fields in ServiceNow before submission. It is particularly useful for ServiceNow developers looking to implement robust data validation mechanisms in user profiles.

This PR also fixed the problem about repo structure, which made the previous PR has been rejected #1534 (comment), I have put the code under existing Background Scripts folder.

How It Works

The snippet uses a business rule that executes on form submission to validate user input:

  • Regular Expressions: It utilizes regex patterns to check the format of the phone and email fields.
  • Error Messaging: If the validation fails, an error message is displayed to the user, and the submission is aborted.

Implementation

  • Add to a Business Rule: This snippet should be incorporated into a business rule configured to run on the user profile table.
  • Adjust Validation Patterns: Modify the phoneNumberPattern and emailPattern variables to align with your specific requirements (e.g: international phone formats).

@sandeepd26 sandeepd26 self-assigned this Oct 29, 2024
Copy link
Contributor

@Lacah Lacah left a comment

Choose a reason for hiding this comment

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

Thanks for resubmitting, but reading the description, it sounds like it should actually be in he Business Rules folder, right?

@wendy-ha18
Copy link
Contributor Author

Hi @Lacah, yeah I just read the folder Business Rules and it seems more suitable with my code snippets.

I have moved the scripts to Business Rules, the folder structure now is:

  • Business Rules/User Profile Field Validation/README.md
  • Business Rules/User Profile Field Validation/userProfileValidation.js

Thanks for your suggestion. Could you please help me review the change again?
Thanks @Lacah

@Lacah Lacah merged commit c577b1b into ServiceNowDevProgram:main Oct 29, 2024
@wendy-ha18 wendy-ha18 deleted the feature/user-profile-field-validation branch October 30, 2024 19:03
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