-
Notifications
You must be signed in to change notification settings - Fork 171
Add Additional Namespace & Catalog Request Support #284
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
base: master
Are you sure you want to change the base?
Conversation
Fixes error "Id must either be a SysId 32 character alphanumeric or Number with prefix and id." and retains ID from reference table for further lookup.
Additional fixes for reference table lookup where value is not in the 32 character format expected by SNOW.
Co-authored-by: Greg Brownstein <greg@jagtechnical.com>
Add Namespace parameter to support different API endpoints; defaults to 'now'
Versioned PSD with Minor increase for new functionality and backwards-compatible changes.
|
Awesome stuff, I'll review this week! |
Add New-ServiceNowCatalog declaration to FunctionsToExport.
gdbarron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much, looks good, just some tweaks here and there :)
| if ($Namespace -ne 'now') { | ||
| $hashOut.Uri = $($ServiceNowSession.BaseUri -split ('api'))[0] + 'api/' + $Namespace | ||
| } else { | ||
| $hashOut.Uri = $ServiceNowSession.BaseUri | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we're better served by changing the baseuri to end with /api and just append the namespace. this will involve changes here and invoke-service nowrestmethod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree and I tried to add the Namespace support functionality with as limited of breaking changes as I could. However, I didn't want to modify the New-ServiceNowSession function where BaseUri is originally declared into script scope variable $ServiceNowSession the due to a lack of familiarity with version specification and GraphQL use cases.
| [string] $FilterString, | ||
|
|
||
| [parameter()] | ||
| [string] $Namespace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default to 'now'?
| if ($namespace) { | ||
| $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession -N $namespace | ||
| } else { | ||
| $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if ($namespace) { | |
| $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession -N $namespace | |
| } else { | |
| $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession | |
| } | |
| $params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession -N $namespace |
|
|
||
| $AddItemCartResponse = Invoke-ServiceNowRestMethod @AddItemToCart | ||
|
|
||
| if ($AddItemCartResponse.cart_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why might we not get a value for cart_id that we need this 'if'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a safety check to make sure the function doesn't continue to checkout if the Invoke results in an error when adding the item to the cart. It may not be necessary but I wanted to be absolutely sure that a checkout wasn't submitted if the Invoke error didn't return a terminating error up the call stack.
Adjusted to include the CheckoutImmediately parameter.
| $SubmitOrderResponse = Invoke-ServiceNowRestMethod @SubmitOrder | ||
| } | ||
| if ( $PassThru ) { | ||
| $SubmitOrderResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $SubmitOrderResponse | |
| $SubmitOrderResponse | Select-Object @{'n'='number';'e'={$_.request_number}}, request_id |
consider updating the output to something like the above so it can be piped directly into the other functions, eg. Get-ServiceNowRecord
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further review of the API documentation, I'm not sure how this would behave when a two-step checkout process is configured.
I do not have a way to test two-step checkout at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: needs to be tested to validate the return behavior when multiple quantities of a catalog item or multiple catalog items are returned from the submit_order POST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be good to have a way to control when checkout occurs in case folks want to add multiple (different) items before submitting order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the CheckoutImmediately switch parameter as well as new function 'Submit-ServiceNowCatalogOrder' to support delayed checkout.
I feel that most use cases will want to use CheckoutImmediately as the default.
|
Thanks, I will review these recommendations after November 5th. |
…pporting ID or name lookup for CatalogItem.
…pporting ID or name lookup for CatalogItem.
This PR adds a cmdlet for New-ServiceNowCatalogItem which uses the 'sn_sc' API namespace to add a catalog item request to a cart and then submits the cart as an order.
Extends Get-ServiceNowAuth and Invoke-ServiceNowRestMethod with a namespace parameter to support different Namespace endpoints; backwards compatibility is maintained by defaulting to the 'now' namespace if not specified.