- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2020 08:31 AM
Hi All,
We have recently integrated ServiceNow with Octopus using PowerShell scripts that create a change request and force state changes to avoid the manual UI process. However this has caused issues (emergency changes error out and users who are in an approval group can approve their own change requests). I have been looking for a way to use the API to call UI actions and avoid the issue of forcing state changes.
I have followed the instructions I found from this link (https://servicenowthink.wordpress.com/2019/10/15/call-any-ui-action-with-rest-api-or-ajax-ootb-updated/):
There is only one endpoint to do POST call for UI actions.
POST @ /api/now/ui/ui_action/${sys_id_of_UI_action}
Additionaly, there are same 3 mandatory body parameters:
sysparm_table – table name of UI action.
sysparm_sys_id – sys_id of the record you want to run UI action against.
api=api (this has to be static).
If your UI action is designed to take additional parameters, you can pass them as well.
Note, if this is not working, you might need to set up Request header with Content-Type application/json and pass body parameters as following:
{
"fields": [ { "name": "" } ]
}
Also, if your UI action contains client side only code, like g_form, it has to be converted to server side for this to work, because without user session being present, g_form and other client side API’s will be equal to null.
When following these instructions exactly, I receive:
"fields": [ { "name": "" } ]
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2020 08:51 AM
We brought in a web developer to assist and he was able to use the admin side to write up a custom script/rule to stop the Requested By user from approving their own changes if they are a member of the approver group.
As I mentioned, this normally works out of box, but because we are using the API to force state changes from a PowerShell in Octopus, this breaks that rule. This custom script prevents that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2020 03:01 PM
I would not call a UI Action via REST, as it requires the UI be loaded to work, typically. REST has no UI. How does Octopus integrate? Is it using REST or screen scraping?
Tapadh leat,
Aoife
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2020 01:19 PM
Hi Aoife,
Here is a sample of code using REST API in a PowerShell script to create a SN change request. We borrowed from the REST API Explorer in SN.
Add-Type -AssemblyName PresentationCore,PresentationFramework
## Variables -- Only the state change variables are listed here
$state = "-4"
$implementState = "0"
## Authorization & Headers ##
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
$headers.Add('Content-Type','application/json')
## Set Methods ##
$methodGet = "get"
$methodPost = "post"
$methodPatch = "patch"
----skipping past other part of the script doing verification----
## SN Script to create new Change request ##
$uriNewChange = "$SNWebURL/api/now/table/change_request?sysparm_display_value=true&sysparm_input_display_value=true"
$bodyNewChange = @{
type = $type
requested_by = "$requestedby"
category = $category
u_subcategory = $subcategory
priority = $priority
risk = $risk
impact = $impact
assignment_group = $assignmentgroup
u_change_manager_group_approval = $changemanagergroupapproval
u_cab_group_approval = $cabgroupapproval
short_description = $shortdescription
description = $description
implementation_plan = $implementationplan
backout_plan = $backoutplan
requested_by_date = $plannedStart
start_date = $plannedStart
end_date = $plannedEnd
state = $state
}
$bodyJsonNewChange = $bodyNewChange | ConvertTo-Json
## Get info from new SN Request created above ##
$responseNewChange = (Invoke-RestMethod -Headers $headers -Method $methodPost -Uri $uriNewChange -Body $bodyJsonNewChange -ContentType "application/json").result
$responseNewChange.number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2020 03:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2020 01:21 PM
Hi Rahul,
I am still new to ServiceNow, and my primary role is in assisting integration, not managing the admin side of ServiceNow. I am not sure where the UI action record would be--is this only an Admin function?
When I am on an open Change Request and I right click on a button, I do get the "Copy URL" option, but it seems to be the same URL for each button/link.