diff --git a/Client-Side Components/Client Scripts/Auto-Populate Short Discription/README.md b/Client-Side Components/Client Scripts/Auto-Populate Short Discription/README.md deleted file mode 100644 index 9c4cedaad9..0000000000 --- a/Client-Side Components/Client Scripts/Auto-Populate Short Discription/README.md +++ /dev/null @@ -1,61 +0,0 @@ - -# Auto-Populate Short Description Client Script - -## Overview - -This client script is designed to enhance the user experience in ServiceNow by automatically populating the 'Short Description' field when a user selects a category for an incident or request. It simplifies the data entry process, ensures consistency in short descriptions, and saves time for users. - -## How It Works - -When a user selects a category from the provided options, the script appends a predefined prefix to the existing 'Short Description' value, creating a more informative short description. - -### Configuration - -To configure and use this client script in your ServiceNow instance, follow these steps: - -1. **Create a Client Script:** - - - Log in to your ServiceNow instance as an admin or developer. - - Navigate to "System Definition" > "Client Scripts." - - Create a new client script and give it a name (e.g., "Auto-Populate Short Description"). - -2. **Copy and Paste the Script:** - - - Copy the JavaScript code provided in this README. - - Paste the code into your newly created client script. - -3. **Attach to 'category' Field:** - - - Save the client script and ensure it's active. - - Attach the client script to the 'category' field of the relevant table (e.g., Incident, Request) where you want to enable this functionality. - -4. **Define Your Category-to-Short-Description Mappings:** - - - Modify the script to define your own mappings for categories and their corresponding short description prefixes. Customize the `categoryToShortDescription` object to match your requirements. - -5. **Testing:** - - - Test the functionality by creating or editing an incident or request record. - - Select a category, and observe how the 'Short Description' field is automatically populated based on your mappings. - -## Example Mapping - -Here's an example of how you can define category-to-short-description mappings in the script: - -```javascript -var categoryToShortDescription = { - 'Hardware': 'Hardware Issue - ', - 'Software': 'Software Issue - ', - 'Network': 'Network Issue - ', - 'Other': 'Other Issue - ' -}; -``` - -You can customize these mappings to align with your organization's specific categories and short description conventions. - -## Benefits - -- Streamlines data entry for users. -- Ensures consistent and informative short descriptions. -- Saves time and reduces the risk of human error. -- Enhances user experience in ServiceNow. diff --git a/Server-Side Components/Background Scripts/Convert Incident Records to JSON/README.md b/Server-Side Components/Background Scripts/Convert Incident Records to JSON/README.md deleted file mode 100644 index 72505c0ced..0000000000 --- a/Server-Side Components/Background Scripts/Convert Incident Records to JSON/README.md +++ /dev/null @@ -1,7 +0,0 @@ -### Overview of Converting Incident Records to JSON - -The provided script fetches all active incident records from the ServiceNow database and converts them into a JSON format. - -### Importance of Understanding JSON in ServiceNow - -In today's complex IT environments, effective data interchange between systems is crucial. JSON has become a standard format for APIs and data exchange due to its simplicity and readability. By understanding how to manipulate JSON in ServiceNow, developers can integrate more seamlessly with external applications, automate workflows, and enhance data processing capabilities. The ability to convert records into JSON format is foundational for working with REST APIs, enabling the sharing of information across platforms. Therefore, providing basic code examples that demonstrate these principles can help developers grasp the importance of JSON, fostering a deeper understanding of how to implement more complex logic in ServiceNow. This foundational knowledge is essential for anyone looking to leverage the full potential of ServiceNow's capabilities in modern IT service management. diff --git a/Server-Side Components/Business Rules/Prevent Null User ID/ReadME.md b/Server-Side Components/Business Rules/Prevent Null User ID/ReadME.md new file mode 100644 index 0000000000..e8d652df7f --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Null User ID/ReadME.md @@ -0,0 +1,39 @@ + +# Prevent Invalid User ID + +## Overview +This **ServiceNow Business Rule** prevents inserting or updating a record when: +- `user_name` is missing or invalid. +- Both `first_name` and `last_name` are missing or invalid. + +## Functionality Breakdown + +### 1. `isInvalid(value)` +- Detects invalid values in user fields. +- Returns `true` if: + - Value is `null`, `undefined`, or empty (`""`) + - Value (after trimming spaces and lowering case) equals `"null"` + +Example: +```javascript +isInvalid(null); // true +isInvalid(""); // true +isInvalid("NULL"); // true +isInvalid("john"); // false +``` + +### 2. `current.setAbortAction(true)` +- Stops the record from being inserted or updated. +- Used inside **Before Business Rules**. +- Prevents saving invalid data to the database. + +### 3. `gs.addErrorMessage("...")` +- Displays a user-friendly error message at the top of the form. +- Helps users understand *why* the save was blocked. + + +## Notes +- Case-insensitive — handles "null", "NULL", "Null", etc. +- Works best in **Before Business Rules** to stop invalid data before saving. +- Adding `gs.addErrorMessage()` helps users understand the validation reason. + diff --git a/Server-Side Components/Business Rules/Prevent Null User ID/script.js b/Server-Side Components/Business Rules/Prevent Null User ID/script.js new file mode 100644 index 0000000000..aa8c50e910 --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Null User ID/script.js @@ -0,0 +1,19 @@ +(function executeRule(current, previous) { + // Utility function to validate if a field is null, empty, or contains "null"/"NULL" + function isInvalid(value) { + return !value || value.toString().trim().toLowerCase() === "null"; + } + + // Abort action if the user_name field is invalid + if (isInvalid(current.user_name)) { + gs.addErrorMessage("User name is invalid"); + current.setAbortAction(true); + } + + // Abort action if both first_name and last_name are invalid + if (isInvalid(current.first_name) && isInvalid(current.last_name)) { + gs.addErrorMessage("Either first name or last name must be provided"); + current.setAbortAction(true); + } + +})(current, previous); \ No newline at end of file