Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"permissions": {
"allow": [
"Bash(find:*)",
"Bash(ls:*)",
"Bash(mkdir:*)",
"Bash(mv:*)",
"Bash(rmdir:*)"
],
"deny": []
}
}
118 changes: 118 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Repository Overview

This is the **ServiceNow Developer Program's Code Snippets Repository** - a community-driven collection of ServiceNow development code examples and utilities. The repository contains 900+ code snippets organized into 50+ categories covering all aspects of ServiceNow platform development.

## Repository Structure and Organization

### Directory Structure
All code snippets follow a standardized four-level structure:
```
Top-Level Category/
β”œβ”€β”€ Sub-Category/
β”‚ β”œβ”€β”€ Specific-Use-Case/
β”‚ β”‚ β”œβ”€β”€ README.md # Description and usage instructions
β”‚ β”‚ β”œβ”€β”€ script.js # Main code implementation
β”‚ β”‚ └── variant.js # Optional code variations
```

### Top-Level Categories (REQUIRED Structure)
The repository is organized into **6 major categories**. All contributions MUST use these categories:

- **Core ServiceNow APIs/**: Essential ServiceNow JavaScript APIs
- `GlideRecord/`, `GlideAjax/`, `GlideSystem/`, `GlideDate/`, `GlideDateTime/`, `GlideElement/`, `GlideFilter/`, `GlideAggregate/`, `GlideHTTPRequest/`, `GlideModal/`, `GlideQuery/`, `GlideTableDescriptor/`

- **Server-Side Components/**: Server-executed code
- `Background Scripts/`, `Business Rules/`, `Script Includes/`, `Script Actions/`, `Scheduled Jobs/`, `Transform Map Scripts/`, `Server Side/`, `Inbound Actions/`, `Processors/`

- **Client-Side Components/**: Browser-executed code
- `Client Scripts/`, `Catalog Client Script/`, `UI Actions/`, `UI Scripts/`, `UI Pages/`, `UI Macros/`, `UX Client Scripts/`, `UX Client Script Include/`, `UX Data Broker Transform/`

- **Modern Development/**: Modern ServiceNow frameworks
- `Service Portal/`, `Service Portal Widgets/`, `NOW Experience/`, `GraphQL/`, `ECMASCript 2021/`

- **Integration/**: External systems and data exchange
- `Integration/` (original), `RESTMessageV2/`, `Import Set API/`, `Scripted REST Api/`, `Mail Scripts/`, `MIDServer/`, `Attachments/`

- **Specialized Areas/**: Domain-specific functionality
- `CMDB/`, `ITOM/`, `Performance Analytics/`, `ATF Steps/`, `Agile Development/`, `Advanced Conditions/`, `Browser Bookmarklets/`, `Browser Utilities/`, `Dynamic Filters/`, `Fix scripts/`, `Flow Actions/`, `Formula Builder/`, `Notifications/`, `On-Call Calendar/`, `Record Producer/`, `Regular Expressions/`, `Styles/`

## Development Guidelines

### Code Quality Standards
- Each snippet must include comprehensive README.md documentation
- Code should be relevant to ServiceNow developers
- ES2021 features are allowed but should be clearly documented
- Examples should expand meaningfully on official ServiceNow documentation
- Quality over quantity - low-effort submissions are rejected

### Contribution Requirements
- **Mandatory Category Structure**: All contributions MUST use the 6 top-level categories. PRs with incorrect structure will be rejected.
- **Descriptive Structure**: Changes must match pull request scope exactly
- **No XML Exports**: Avoid ServiceNow record exports in favor of JavaScript code
- **Documentation**: Every code snippet requires accompanying README.md
- **Proper Categorization**: Place snippets in appropriate existing sub-categories within the required top-level structure

### File Organization
- Use descriptive folder names that clearly indicate functionality
- Group related code variations in the same folder
- Include screenshots or examples when helpful for understanding
- Maintain consistent naming conventions across similar snippets

## Common ServiceNow Development Patterns

### GlideRecord Usage
- Most snippets demonstrate proper GlideRecord query patterns
- Security considerations with ACL enforcement examples
- Performance optimization through proper query construction
- Reference field handling and relationship traversal

### Integration Patterns
- REST API consumption and production examples
- Authentication handling for external systems
- Data transformation and mapping utilities
- Error handling and logging best practices

### Business Logic Implementation
- Business Rules for event-driven processing
- Background Scripts for administrative tasks
- Client Scripts for form behavior and validation
- UI Actions for custom user interactions

## Testing and Validation

### Code Verification
- Test all code snippets in development environments before submission
- Validate against multiple ServiceNow versions when possible
- Consider security implications and access controls
- Document any prerequisites or dependencies

### Community Review Process
- All contributions undergo peer review by Developer Advocates
- Changes outside described scope result in rejection
- Multiple submissions require separate branches in forked repositories

## Security Considerations

- Never include sensitive information (passwords, API keys, tokens)
- Consider security implications of all code examples
- Demonstrate proper access control patterns where applicable
- Include warnings for potentially dangerous operations

## Repository Maintenance

### Branch Management
- Main branch contains all approved code snippets
- Use descriptive branch names for contributions
- Create separate branches for different feature additions

### File Management
- No build processes or compilation required
- Direct GitHub editing supported
- Git-enabled IDEs like VS Code recommended for larger contributions
- Standard .gitignore excludes only .DS_Store files

This repository serves as a comprehensive reference for ServiceNow developers at all skill levels, emphasizing practical, tested solutions for real-world development scenarios.
66 changes: 43 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,57 @@ If you plan to submit another pull request while your original is still pending,

## Repository Structure

**IMPORTANT**: The repository has been reorganized into major categories. All new contributions MUST follow this structure for PR approval.

Please follow this directory structure when organizing your code snippets:

- **Top-Level Folders**: These should represent categories of snippets (e.g., `fruits`, `vegetables`).
- **Sub-Folders**: Each top-level folder should contain a sub-folder for **each code snippet**.
- **Snippet Folder Contents**: Within each sub-folder, include:
- A `readme.md` file that describes the code snippet.
- **Top-Level Categories**: These are fixed categories that represent major areas of ServiceNow development:
- `Core ServiceNow APIs/` - GlideRecord, GlideAjax, GlideSystem, GlideDate, etc.
- `Server-Side Components/` - Background Scripts, Business Rules, Script Includes, etc.
- `Client-Side Components/` - Client Scripts, Catalog Client Scripts, UI Actions, etc.
- `Modern Development/` - Service Portal, NOW Experience, GraphQL, ECMAScript 2021
- `Integration/` - RESTMessageV2, Import Sets, Mail Scripts, MIDServer, etc.
- `Specialized Areas/` - CMDB, ITOM, Performance Analytics, ATF Steps, etc.

- **Sub-Categories**: Each top-level category contains sub-folders for specific ServiceNow technologies or use cases.
- **Snippet Folders**: Each sub-category contains folders for **each code snippet**.
- **Snippet Folder Contents**: Within each snippet folder, include:
- A `README.md` file that describes the code snippet.
- Individual files for each variant of the code snippet.

### Example Structure
### New Structure Example

```
.github
fruits
β”œβ”€β”€ apples
β”‚ β”œβ”€β”€ readme.md # Description of the apples code snippet
β”‚ β”œβ”€β”€ apples.js # First code snippet for apples
β”‚ └── fijiapples.js # Variation of the apples snippet
└── kiwi
β”œβ”€β”€ readme.md # Description of the kiwi code snippet
└── kiwi.js # Code snippet for kiwi
vegetables
β”œβ”€β”€ carrots
β”‚ β”œβ”€β”€ readme.md # Description of the carrots code snippet
β”‚ └── carrots.js # Code snippet for carrots
└── potatoes
β”œβ”€β”€ readme.md # Description of the potatoes code snippet
β”œβ”€β”€ potatoes.js # Original code snippet for potatoes
β”œβ”€β”€ yukongoldpotato.js # Variant for Yukon Gold potatoes
└── tatertots.js # Variant for tater tots
Core ServiceNow APIs/
β”œβ”€β”€ GlideRecord/
β”‚ β”œβ”€β”€ Query Performance Optimization/
β”‚ β”‚ β”œβ”€β”€ README.md # Description of the optimization snippet
β”‚ β”‚ β”œβ”€β”€ basic_query.js # Basic query example
β”‚ β”‚ └── optimized_query.js # Performance-optimized version
β”‚ └── Reference Field Handling/
β”‚ β”œβ”€β”€ README.md # Description of reference handling
β”‚ └── reference_query.js # Reference field query example
└── GlideAjax/
β”œβ”€β”€ Async Data Loading/
β”‚ β”œβ”€β”€ README.md # Description of async loading
β”‚ β”œβ”€β”€ client_script.js # Client-side implementation
β”‚ └── script_include.js # Server-side Script Include
Server-Side Components/
β”œβ”€β”€ Business Rules/
β”‚ β”œβ”€β”€ Auto Assignment Logic/
β”‚ β”‚ β”œβ”€β”€ README.md # Description of auto assignment
β”‚ β”‚ └── assignment_rule.js # Business rule implementation
```

### Category Placement Guidelines

- **Core ServiceNow APIs**: All Glide* APIs and core ServiceNow JavaScript APIs
- **Server-Side Components**: Code that runs on the server (Business Rules, Background Scripts, etc.)
- **Client-Side Components**: Code that runs in the browser (Client Scripts, UI Actions, etc.)
- **Modern Development**: Modern ServiceNow development approaches and frameworks
- **Integration**: External system integrations, data import/export, and communication
- **Specialized Areas**: Domain-specific functionality (CMDB, ITOM, Testing, etc.)

## Final Checklist

Before submitting your pull request, ensure that:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
# 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.

# 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.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// Client Script to Auto-Populate Short Description based on Category
function onChangeCategory() {
var categoryField = g_form.getValue('category'); // Get the selected category
var shortDescriptionField = g_form.getValue('short_description'); // Get the Short Description field
// Define mappings for categories and corresponding short descriptions
var categoryToShortDescription = {
'Hardware': 'Hardware Issue - ',
'Software': 'Software Issue - ',
'Network': 'Network Issue - ',
'Other': 'Other Issue - '
};
// Update Short Description based on the selected category
if (categoryToShortDescription.hasOwnProperty(categoryField)) {
var newShortDescription = categoryToShortDescription[categoryField] + shortDescriptionField;
g_form.setValue('short_description', newShortDescription);
}
}
// Attach the onChangeCategory function to the 'category' field
g_form.observe('change', 'category', onChangeCategory);
// Client Script to Auto-Populate Short Description based on Category

function onChangeCategory() {
var categoryField = g_form.getValue('category'); // Get the selected category
var shortDescriptionField = g_form.getValue('short_description'); // Get the Short Description field

// Define mappings for categories and corresponding short descriptions
var categoryToShortDescription = {
'Hardware': 'Hardware Issue - ',
'Software': 'Software Issue - ',
'Network': 'Network Issue - ',
'Other': 'Other Issue - '
};

// Update Short Description based on the selected category
if (categoryToShortDescription.hasOwnProperty(categoryField)) {
var newShortDescription = categoryToShortDescription[categoryField] + shortDescriptionField;
g_form.setValue('short_description', newShortDescription);
}
}

// Attach the onChangeCategory function to the 'category' field
g_form.observe('change', 'category', onChangeCategory);
Loading
Loading