REST Table API to trigger a Catalog Item request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2016 02:24 PM
Hello.
I'm working on an external form for users to fill out and submit into SN via the REST Table API.
If I create a catalog item in SN, is it possible to use this API to request this catalog item by inserting a new record into the Service Catalog Requested Item [sc_req_item] table, and thereby triggering the corresponding approval workflow? Will this work?
If yes, will need to figure out what required fields to be populated at a minimum in order for this to work.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2016 08:50 AM
Thx Van,
I think I will investigate your recommendation of creating a catalog item using the ServiceNow provided Cart API. It might give me the pieces I seem to be missing in my workflow. Up to now, I was using a workflow that was based on a table to extends Task, and populated by REST, thinking I could get the same functionality. Btw I am now working with Geneva but I think the Cart API script you mentioned would work the same there I hope.
One thing I'm still not clear on regarding Task, and I'm hoping you help clear up: In the workflow, when I add a Create Task activity, you can pick from many Task types. It defaults to Task[task] but I have been using Catalog Task[sc_task] in order for the user to see it assigned to him when he logs into ServiceNow. He sees it under 'Service Desk > My Work' in the menu. If I use the default Task type, Task[task], the Task will not show for the user. Why is that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2016 05:03 PM
I just got this working on my end. Just starting out with Service Now so take what I say with a grain of salt.
I first tried creating the request, requested item, and tasks manually via REST - tying them all together with sysid's. Everything "looked" fine. But the workflows attached to the items I was "ordering" didn't trigger until I manually opened a requested item and saved it again - that was no good for me.
So, turns out you can use Scripted Web Services (uses SOAP - not REST yet.) to trigger stuff that you can't via REST table inserts. So you essentially write up javascript that executes within Service Now (against their glide api), but you can trigger this script via a SOAP call (complete with your parameters). It looks like triggering these scripts via REST is coming in Geneva, if not soon after.
In the fuji developer instance, there is a scripted web service called "OrderBlackBerry". I was able to run a powershell script from my own workstation to get this script to activate and create a whole new order. I created my own web service after using this as a template. Now able to "order" items and the associated Workflow kicks off correctly. No new tables being created, no diving into the schema.
Since powershell with SOAP is no fun, here's some code in case someone finds it useful or can at least use that as a starting point in another language:
Function OrderBlackBerry($cred){
$url = "https://devXXXXX.service-now.com/OrderBlackBerry.do?WSDL"
# Random namespace to get around a web proxy caching issues which breaks stuff, only letting this script work once per powershell session.
# So we'll put in a random namespace to avoid this problem and let .NET clean this up on its own time.
$randoNameSpace = ("NS-" + [System.Guid]::NewGuid().ToString()).Replace('-','')
$service = New-WebServiceProxy -Uri $url -namespace $randoNameSpace -Credential $cred
$type = $service.GetType().NameSpace
$myOrder = New-Object ($type + ".order")
# hard-coded for testing
$myorder.phone_number = "999.444.7777"
$myorder.requested_for = "abel.tuter"
$request = $service.order($myorder)
}