Here's How to Write a Scripted REST API to Get Catalog Item Variables in ServiceNow via REST!

Tim Woodruff
Mega Guru

Howdy folks!

I recently wrote an article on how to create a scripted REST API to retrieve catalog item variables via REST (something you couldn't do previously, in Geneva and earlier), so I thought I'd share.

In helsinki, there's the sn_sc API that might make this possible, but this is still a quick and easy way to accomplish that, and for anyone still on Geneva or earlier, something like this is your only option for getting catalog item variables via web services.

SN Pro Tips — ServiceNow Scripted REST APIs & Retrieving Catalog Item Variables

Let me know your thoughts, and if you enjoy the article, I humbly welcome you to subscribe for more. 🙂

-Tim

9 REPLIES 9

Jace Benson
Mega Sage

Hey Tim, this is cool.   I know we did something similar at Expedia that was shared here;



ServiceNow Share


And it's tasks returned the variables, not shown in screenshots


Screenshot from 2016-08-04 12-07-35.png



But this uses processor instead of the new scripted rest api's


Thanks Jace! Hope things are going swimmingly for all you folks over at Expedia. 🙂


We used your processor and script include and it works great! Do you know what would need to be tweaked to return back the sysIDs of all the variables as well as additional values such help text and tool tips?


Not sure where you want those things.



If when quering for a item to request, you'd have to modify the method, `getCatalogItem`


If you are asking that when you request a task and its variables you'd have to modify the method, `getTask`



the getCatalogItem has teh properties you want so you should just be able to add them with code something like;


if (vars.default_value.toString() !== '') {
  objToPush.column= vars.column.toString();
    }



the getTask would be more difficult as you'd have to query the item definition for that item.