|
| 1 | +--- |
| 2 | +# PR Description: |
| 3 | + |
| 4 | +This pull request adds a Scripted REST API for ServiceNow that creates Incident records in the domain and company of the authenticated user. The API was developed as part of a Hacktoberfest 2025 contribution and is intended for educational and demonstration purposes. The `create` method ensures incidents are scoped to the user's domain, supporting multi-tenancy and domain separation best practices. |
| 5 | +--- |
| 6 | + |
| 7 | +# Pull Request Checklist |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +- [x] I have read and understood the [CONTRIBUTING.md](CONTRIBUTING.md) guidelines |
| 12 | +- [x] My pull request has a descriptive title that accurately reflects the changes |
| 13 | +- [x] I've included only files relevant to the changes described in the PR title and description |
| 14 | +- [x] I've created a new branch in my forked repository for this contribution |
| 15 | + |
| 16 | +## Code Quality |
| 17 | + |
| 18 | +- [x] My code is relevant to ServiceNow developers |
| 19 | +- [x] My code snippets expand meaningfully on official ServiceNow documentation (if applicable) |
| 20 | +- [x] I've disclosed use of ES2021 features (if applicable) |
| 21 | +- [x] I've tested my code snippets in a ServiceNow environment (where possible) |
| 22 | + |
| 23 | +## Repository Structure Compliance |
| 24 | + |
| 25 | +- [x] I've placed my code snippet(s) in one of the required top-level categories: |
| 26 | + - `Server-Side Components/` |
| 27 | +- [x] I've used appropriate sub-categories within the top-level categories |
| 28 | +- [x] Each code snippet has its own folder with a descriptive name |
| 29 | + |
| 30 | +## Documentation |
| 31 | + |
| 32 | +- [x] I've included a README.md file for each code snippet |
| 33 | +- [x] The README.md includes: |
| 34 | + - [x] Description of the code snippet functionality |
| 35 | + - [x] Usage instructions or examples |
| 36 | + - [x] Any prerequisites or dependencies |
| 37 | + - [x] (Optional) Screenshots or diagrams if helpful |
| 38 | + |
| 39 | +## Restrictions |
| 40 | + |
| 41 | +- [x] My PR does not include XML exports of ServiceNow records |
| 42 | +- [x] My PR does not contain sensitive information (passwords, API keys, tokens) |
| 43 | +- [x] My PR does not include changes that fall outside the described scope |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +````markdown |
| 48 | +# 🎃 Hacktoberfest 2025 Contribution: ServiceNow Scripted REST API |
| 49 | + |
| 50 | +## Overview |
| 51 | + |
| 52 | +This repository contains a **Scripted REST API** developed for **ServiceNow** as part of a Hacktoberfest 2025 contribution. The API allows authenticated users to create new **Incident** records within their own domain and company context. |
| 53 | + |
| 54 | +> **DISCLAIMER** |
| 55 | +> This script was developed and tested on a **ServiceNow Personal Developer Instance (PDI)**. |
| 56 | +> It is intended for **educational and demonstration purposes only**. |
| 57 | +> Please **test thoroughly in a dedicated development environment** before deploying to production. |
| 58 | +
|
| 59 | +--- |
| 60 | + |
| 61 | +## Features |
| 62 | + |
| 63 | +- Creates a new Incident record for the currently logged-in user. |
| 64 | +- Automatically assigns the user's domain and company to the incident. |
| 65 | +- Returns the generated incident number and domain in the response. |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Script Details |
| 70 | + |
| 71 | +- **Author**: Anasuya Rampalli ([anurampalli](https://github.com/anurampalli)) |
| 72 | +- **Version**: 1.0 |
| 73 | +- **Date**: 2025-10-08 |
| 74 | +- **Context**: Scripted REST API (`create` function) |
| 75 | +- **Tested On**: ServiceNow Personal Developer Instance (PDI) |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## 📥 Expected Request Format |
| 80 | + |
| 81 | +```json |
| 82 | +POST /api/your_namespace/your_endpoint |
| 83 | +Content-Type: application/json |
| 84 | + |
| 85 | +{ |
| 86 | + "short_description": "Issue description text" |
| 87 | +} |
| 88 | +``` |
| 89 | +```` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Response Examples |
| 94 | + |
| 95 | +### Success |
| 96 | + |
| 97 | +```json |
| 98 | +{ |
| 99 | + "status": "success", |
| 100 | + "incident_id": "INC0012345", |
| 101 | + "domain": "TOP/Child Domain" |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +### Error |
| 106 | + |
| 107 | +```json |
| 108 | +{ |
| 109 | + "error": { |
| 110 | + "message": "User Not Authenticated", |
| 111 | + "detail": "Required to provide Auth information" |
| 112 | + }, |
| 113 | + "status": "failure" |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## 📚 How It Works |
| 120 | + |
| 121 | +1. Extracts the `short_description` from the incoming JSON payload. |
| 122 | +2. Identifies the authenticated user via `gs.getUserID()`. |
| 123 | +3. Retrieves the user's domain and company using `sys_user`. |
| 124 | +4. Creates a new `incident` record with the user's domain, company, and description. |
| 125 | +5. Returns the incident number and domain in the response. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## 🧪 Testing Tips |
| 130 | + |
| 131 | +- Use a valid ServiceNow PDI with Scripted REST API enabled. |
| 132 | +- Ensure the user is authenticated before making requests. |
| 133 | +- Check the `incident` table for newly created records. |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## 🤝 Contributing |
| 138 | + |
| 139 | +Pull requests are welcome! If you'd like to improve this script or adapt it for other use cases, feel free to fork and submit your changes. |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## 📄 License |
| 144 | + |
| 145 | +This project is open-source and available under the [MIT License](LICENSE). |
| 146 | + |
| 147 | +--- |
0 commit comments