-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[21144] feat(servicenow): Add new actions across service-catalog, knowledge-base #21190
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28a50f9
feat(servicenow): add new actions across service-catalog, knowledge-base
ashwins01 d0d9272
chore(servicenow): update package versions
ashwins01 ed1238d
Merge branch 'master' into issue-21144-servicenow
ashwins01 f4680f4
fix(servicenow): default cart quantity, fix view-cart count, centrali…
ashwins01 40dcf23
Merge branch 'master' into issue-21144-servicenow
ashwins01 c29b8ea
Merge branch 'master' into issue-21144-servicenow
ashwins01 ad40233
Merge branch 'master' into issue-21144-servicenow
vetrivigneshwaran 806de87
Merge branch 'master' into issue-21144-servicenow
ashwins01 2b32c6f
fix(servicenow): correct cart actions and consolidate duplicate endpo…
ashwins01 8c99050
Merge branch 'master' into issue-21144-servicenow
ashwins01 d4e464f
fix(servicenow): address review comments
ashwins01 0eed20c
Merge branch 'master' into issue-21144-servicenow
ashwins01 505b8af
Merge branch 'master' into issue-21144-servicenow
ashwins01 6ce4e34
fix(servicenow): add defensive-check for encoded queries
ashwins01 58c65e1
chore(servicenow): bump patch version
ashwins01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
components/servicenow/actions/add-item-to-cart/add-item-to-cart.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-add-item-to-cart", | ||
| name: "Add Item to Cart", | ||
| description: "Add a ServiceNow catalog item to the current user's cart. Run **Search Catalog Items** to find the item `sys_id` and **Get Catalog Item Variables** to learn which variable names to supply. After adding items, use **View Cart**, then **Checkout Cart** or **Submit Cart Order** to submit. [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_ServiceCatalogAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| catalogItemSysId: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "catalogItemSysId", | ||
| ], | ||
| description: "The `sys_id` of the catalog item to add. Run **Search Catalog Items** first to find this value. Example: `e8d3d2f1c0a8016400e6b9e0f6e6f6e6`.", | ||
| }, | ||
| quantity: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "quantity", | ||
| ], | ||
| }, | ||
| variables: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "variables", | ||
| ], | ||
| }, | ||
| requestedFor: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "requestedFor", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.servicenow.addItemToCart({ | ||
| $, | ||
| catalogItemSysId: this.catalogItemSysId, | ||
| data: { | ||
| sysparm_quantity: this.quantity, | ||
| variables: parseObject(this.variables), | ||
| sysparm_requested_for: this.requestedFor, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully added catalog item ${this.catalogItemSysId} to cart`); | ||
|
|
||
| return response; | ||
| }, | ||
| }; |
62 changes: 62 additions & 0 deletions
62
components/servicenow/actions/check-order-status/check-order-status.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
| import { assertSafeQueryValue } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-check-order-status", | ||
| name: "Check Order Status", | ||
| description: "Retrieve the status of a ServiceNow catalog request (REQ) from the `sc_request` table, including request state, approval, and stage. Provide the request number returned by **Checkout Cart**, **Submit Cart Order**, or **Order Catalog Item**. [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_TableAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| requestNumber: { | ||
| type: "string", | ||
| label: "Request Number", | ||
| description: "The request number to look up (matched against `number` on `sc_request`). Example: `REQ0010001`.", | ||
|
vetrivigneshwaran marked this conversation as resolved.
|
||
| }, | ||
| requestedFor: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "requestedFor", | ||
| ], | ||
| description: "Optional `sys_id` of the requested-for user to additionally filter by (matched against `requested_for` on `sc_request`). Run **Find Users** to find it.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| assertSafeQueryValue(this.requestNumber, "Request Number"); | ||
| assertSafeQueryValue(this.requestedFor, "Requested For"); | ||
|
|
||
| const queryParts = [ | ||
| `number=${this.requestNumber}`, | ||
| ]; | ||
| if (this.requestedFor) { | ||
| queryParts.push(`requested_for=${this.requestedFor}`); | ||
| } | ||
| const response = await this.servicenow.getRequests({ | ||
| $, | ||
| params: { | ||
| sysparm_query: queryParts.join("^"), | ||
| sysparm_limit: 1, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }, | ||
| }); | ||
|
|
||
| const request = response?.[0]; | ||
| let summary; | ||
| if (!request) { | ||
| summary = `No request found with number ${this.requestNumber}`; | ||
| } else { | ||
| const state = request.state ?? request.request_state; | ||
| summary = state | ||
| ? `Retrieved status for request ${this.requestNumber}: ${state}` | ||
| : `Retrieved status for request ${this.requestNumber}`; | ||
| } | ||
| $.export("$summary", summary); | ||
|
|
||
| return response; | ||
| }, | ||
| }; | ||
30 changes: 30 additions & 0 deletions
30
components/servicenow/actions/checkout-cart/checkout-cart.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-checkout-cart", | ||
| name: "Checkout Cart", | ||
| description: "Submit the current user's ServiceNow cart via the standard `/cart/checkout` endpoint, generating a request (REQ). The result depends on the instance's one-step vs two-step checkout configuration (in two-step mode it returns the order summary/status to confirm rather than finalizing). Add items first with **Add Item to Cart** and inspect with **View Cart**. Use **Check Order Status** afterward to track the resulting request. [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_ServiceCatalogAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.servicenow.checkoutCart({ | ||
| $, | ||
| }); | ||
|
|
||
| const requestNumber = response?.request_number ?? response?.number ?? response?.request_id; | ||
| const summary = requestNumber | ||
| ? `Successfully checked out cart - request ${requestNumber}` | ||
| : "Successfully checked out cart"; | ||
| $.export("$summary", summary); | ||
|
|
||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
components/servicenow/actions/delete-cart-item/delete-cart-item.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-delete-cart-item", | ||
| name: "Delete Cart Item", | ||
| description: "Remove an item from the current user's ServiceNow cart. Run **View Cart** first to obtain the `cart_item` id to delete. This permanently removes the line item from the cart. [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_ServiceCatalogAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: true, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| cartItemId: { | ||
| type: "string", | ||
| label: "Cart Item ID", | ||
| description: "The cart item id to remove. Run **View Cart** first to find this value. Example: `0f3b2e2e1b223010d3f5a6c1cd4bcb12`.", | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.servicenow.deleteCartItem({ | ||
| $, | ||
| cartItemId: this.cartItemId, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully removed cart item ${this.cartItemId}`); | ||
|
|
||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-empty-cart", | ||
| name: "Empty Cart", | ||
| description: "Empty and delete the current user's ServiceNow cart, removing all of its items. The action resolves the active cart automatically, so no cart ID is required. Emptying a cart that still has items requires the `catalog_admin` role (a plain `admin` can only delete an already-empty cart). [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_ServiceCatalogAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: true, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| }, | ||
| async run({ $ }) { | ||
| const { cart_id: cartSysId } = await this.servicenow.getCart({ | ||
| $, | ||
| }); | ||
|
|
||
| const response = await this.servicenow.emptyCart({ | ||
| $, | ||
| cartSysId, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully emptied cart ${cartSysId}`); | ||
|
|
||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
| import { assertSafeQueryValue } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-find-users", | ||
| name: "Find Users", | ||
| description: "Search ServiceNow `sys_user` records to find a user's `sys_id` (used by props like the requested-for field on **Add Item to Cart**). Choose whether to match on name (partial) or email (exact). [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_TableAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| searchField: { | ||
| type: "string", | ||
| label: "Search Field", | ||
| description: "Which `sys_user` field to match on. `Name` performs a partial (contains) match; `Email` requires an exact match.", | ||
| options: [ | ||
| { | ||
| label: "Name (partial match)", | ||
| value: "name", | ||
| }, | ||
| { | ||
| label: "Email (exact match)", | ||
| value: "email", | ||
| }, | ||
| ], | ||
| default: "name", | ||
| }, | ||
| searchValue: { | ||
| type: "string", | ||
| label: "Search Value", | ||
| description: "The value to search for. Example: `Jane Doe` or `jane.doe@example.com`.", | ||
| }, | ||
| limit: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "limit", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| assertSafeQueryValue(this.searchValue, "Search Value"); | ||
|
|
||
| const operator = this.searchField === "name" | ||
| ? "LIKE" | ||
| : "="; | ||
| const response = await this.servicenow.listUsers({ | ||
| $, | ||
| params: { | ||
| sysparm_query: `${this.searchField}${operator}${this.searchValue}`, | ||
| sysparm_limit: this.limit, | ||
| }, | ||
| }); | ||
|
|
||
| const users = Array.isArray(response) | ||
| ? response | ||
| : []; | ||
| $.export("$summary", `Found ${users.length} user(s) matching ${this.searchField} "${this.searchValue}"`); | ||
|
|
||
| return response; | ||
| }, | ||
| }; |
36 changes: 36 additions & 0 deletions
36
components/servicenow/actions/get-catalog-item-variables/get-catalog-item-variables.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import servicenow from "../../servicenow.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "servicenow-get-catalog-item-variables", | ||
| name: "Get Catalog Item Variables", | ||
| description: "Retrieve the ordered variables (form fields) for a ServiceNow catalog item. Run **Search Catalog Items** first to obtain the item `sys_id`, then use the returned variable names to build the `variables` payload for **Add Item to Cart**, **Order Catalog Item**, or **Submit Record Producer**. [See the documentation](https://www.servicenow.com/docs/r/zurich/api-reference/rest-apis/c_ServiceCatalogAPI.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| servicenow, | ||
| catalogItemSysId: { | ||
| propDefinition: [ | ||
| servicenow, | ||
| "catalogItemSysId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.servicenow.getCatalogItemVariables({ | ||
| $, | ||
| catalogItemSysId: this.catalogItemSysId, | ||
| }); | ||
|
|
||
| const variables = Array.isArray(response) | ||
| ? response | ||
| : (response?.variables ?? []); | ||
| $.export("$summary", `Successfully retrieved ${variables.length} variable(s) for catalog item ${this.catalogItemSysId}`); | ||
|
|
||
| return variables; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.