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 index 7bf56626d9..4dab2bdbd8 100644 --- a/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Readme.md +++ b/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Readme.md @@ -1,45 +1,36 @@ -Auto-Populate Short Description (Client Script) -Overview +# Auto-Populate Short Description (Client Script) +## Overview This client script automatically updates the Short Description field in ServiceNow whenever a user selects a category on the form. It improves data consistency, saves time, and ensures that short descriptions remain meaningful and standardized. -How It Works +## How It Works When a user selects a category such as Hardware, Software, or Network, the script automatically prefixes the existing short description with a corresponding label (for example, “Hardware Issue –”). This makes incident records easier to identify and improves the quality of data entry. -Configuration Steps +## Configuration Steps -Log in to your ServiceNow instance with admin or developer access. - -Navigate to System Definition → Client Scripts. - -Create a new Client Script with the following details: +1. Log in to your ServiceNow instance with admin or developer access. +2. Navigate to System Definition → Client Scripts. +3. Create a new Client Script with the following details: +``` Table: Incident - Type: onChange - Field name: category - Copy and paste the provided script into the Script field. - Save the record and make sure the script is active. +``` -Testing +## Testing -Open any existing or new Incident record. +1. Open any existing or new Incident record. +2. Select a category such as Hardware or Software. +3. The Short Description field will automatically update with the corresponding prefix. -Select a category such as Hardware or Software. - -The Short Description field will automatically update with the corresponding prefix. - -Benefits +## Benefits Speeds up data entry for users. - Maintains consistency in short descriptions. - Reduces manual effort and human errors. - Enhances clarity in incident listings and reports. diff --git a/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/Bulk Change of Incident Priority Based on Category.js b/Server-Side Components/Background Scripts/Bulk Change of Incident Priority Based on Category/Bulk Change of Incident Priority Based on Category.js similarity index 100% rename from Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/Bulk Change of Incident Priority Based on Category.js rename to Server-Side Components/Background Scripts/Bulk Change of Incident Priority Based on Category/Bulk Change of Incident Priority Based on Category.js diff --git a/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/README.md b/Server-Side Components/Background Scripts/Bulk Change of Incident Priority Based on Category/README.md similarity index 100% rename from Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/README.md rename to Server-Side Components/Background Scripts/Bulk Change of Incident Priority Based on Category/README.md 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 index 9a4b8ad5d5..565466e9ba 100644 --- 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 @@ -1,24 +1,100 @@ -Convert Active Incidents to JSON – ServiceNow -Overview +# Active Incidents JSON Export – ServiceNow -This script fetches all active Incident records from your ServiceNow instance and converts them into a JSON format. The JSON output is easy to read and can be used for reporting, integration, or debugging purposes. +This repository contains **two approaches** to fetch active incidents from ServiceNow and convert them to JSON. Both use `GlideRecord` but differ in flexibility and readability. -By converting records to JSON, you can quickly share structured data with external systems, automate processes, or use it in scripts and dashboards. +--- -Features +## 1. Simple Approach -Retrieves all active incidents from the incident table. +This method fetches a **fixed set of fields** and converts them directly to JSON. -Dynamically extracts selected fields (configurable). +```javascript +var incidents = []; +var gr = new GlideRecord('incident'); +gr.addQuery('active', true); +gr.query(); +while (gr.next()) { + incidents.push({ + number: gr.number.toString(), + short_description: gr.short_description.toString(), + state: gr.state.toString(), + assigned_to: gr.assigned_to.getDisplayValue('name'), + created_on: gr.sys_created_on.getDisplayValue() + }); +} -Automatically resolves reference fields to display values. +var jsonOutput = JSON.stringify(incidents); +gs.info(jsonOutput); +``` -Adds human-readable state labels (e.g., "New", "In Progress", "Resolved"). +### ✅ Pros +- Simple and easy to implement +- Works fine for a fixed set of fields +- Direct JSON output -Outputs pretty-printed JSON for easy readability. +### ❌ Cons +- Fields are hard-coded → not reusable for other tables +- Reference fields handling is not dynamic +- Numeric state values are not human-readable -Configuration +--- -Table Name: Set the tableName variable to the table you want to extract records from. +## 2. Flexible & Dynamic Approach -Fields to Include: Update the fieldsToInclude array to include the fields you need in the JSON. For example: +This method allows dynamic fields, handles reference fields, and adds human-readable state labels. + +```javascript +var tableName = 'incident'; +var fieldsToInclude = ['number', 'short_description', 'state', 'assigned_to', 'sys_created_on']; +var incidentList = []; + +var gr = new GlideRecord(tableName); +gr.addQuery('active', true); +gr.query(); + +while (gr.next()) { + var incidentObj = {}; + + fieldsToInclude.forEach(function(field) { + if (gr.isValidField(field) && gr[field].getRefRecord) { + incidentObj[field] = gr[field].getDisplayValue(); + } else if (gr.isValidField(field)) { + incidentObj[field] = gr[field].toString(); + } else { + incidentObj[field] = null; + } + }); + + // Map numeric state to human-readable label + var stateMap = { + '1': 'New', + '2': 'In Progress', + '3': 'On Hold', + '6': 'Resolved', + '7': 'Closed' + }; + incidentObj.state_label = stateMap[incidentObj.state] || 'Unknown'; + + incidentList.push(incidentObj); +} + +var jsonOutput = JSON.stringify(incidentList, null, 2); +gs.info("Here's your JSON for active incidents:\n" + jsonOutput); +``` + +### ✅ Pros +- Dynamic → easily reusable for any table and fields +- Handles reference fields gracefully +- Adds human-readable state labels +- JSON is formatted for readability +- Checks `isValidField` to prevent errors + +### ❌ Cons +- Slightly more complex than the simple version +- Requires manual mapping for fields like state labels + + +## Summary + +- **Simple Approach**: Best for quick tasks with fixed fields +- **Flexible Approach**: Best for reusable scripts, handling dynamic tables, reference fields, and human-readable output \ No newline at end of file diff --git a/Specialized Areas/Fix scripts/updateMultipleRecords/readme.md b/Specialized Areas/Fix scripts/updateMultipleRecords/readme.md index fac705ce21..3d914a4e98 100644 --- a/Specialized Areas/Fix scripts/updateMultipleRecords/readme.md +++ b/Specialized Areas/Fix scripts/updateMultipleRecords/readme.md @@ -1,8 +1,15 @@ -************* -This script will query the group table and look for groups with inactive members. The script will replace the inactive manager with the oldest active member of the group. +## update Multiple Records +These 2 scripts are used to update Multiple records but in different ways +### update_multiple_records.script file +In this script it uses `updateMultiple()` Function +1. In this script it uses `updateMultiple()` Function +2. Automatically updates system fields like sys_updated_by and sys_updated_on. +3. Cannot skip system fields using autoSysFields(false). +4. Always triggers workflows, business rules, and script actions. +5. Cannot disable per record. -Logs: If no active members are there in group //gs.info("Group " + grp.name + " does not have any active user"); - -After manager is replaced : gs.info("Group " + inactiveMgrGrp.name + " manager changed to " + getOlderGroupMember(inactiveMgrGrp).name); - -************* +### update_multiple_records_v2.script file +In this script it uses `update()` Function +1. update() is a GlideRecord method used to update a single record in the database. It is commonly used inside a loop to update multiple records individually. +2. Can skip updating system fields using autoSysFields(false). +3. Can skip workflows/business rules using setWorkflow(false). \ No newline at end of file