create service catalog item via script

philbool
Giga Expert

I have inherited a large catalog with about 400 requestable catalog items with workflows and variables.   I come from a service management, rather than development background, so whilst my JS skills are growing fast, I am still struggling to put framework around new concepts and ideas and would be very grateful for your help.

All my catalog items have a product model associated with them that holds values that determine the approval processes required.   Please don't ask why these values are there rather than on the catalog item - this was an Itil / uniformity inspired senior management decision, not mine.

Anyway, as a result, all the data that I need to create a new requestable catalog item for a piece of software is in my software model table.   I would like to use a script to create a catalog item from a product model, and trigger this from a workflow on the software model table.   This script would run when a new software request has been completed.

I appreciate I need to use the run Script activity, but can anyone give me any advice on what kind of script would do this, and what it would look like?

1 ACCEPTED SOLUTION

No worries.   In your script, add this as the last line:


cat_item.insert();


View solution in original post

5 REPLIES 5

philbool
Giga Expert

I've tried the following, running as a Run Script in a workflow triggered by record producer that creates a software model.   At present, I can't find any evidence that this is creating anything at all, so presume I'm missing something obvious...




var cat_item = new GlideRecord('sc_cat_item');



cat_item.newRecord();   // Creates a new item on the table, assigns a sys_id, and populates the default values


cat_item.name = ('test');


cat_item.active = ('true');


cat_item.no_quantity = ('true');


cat_item.delivery_time = ('30 Days');


cat_item.omit_price = ('true');


cat_item.category = 'Application Store';


cat_item.description = 'Test Item Generated By Script';


cat_item.model = ('test');


JordanLind
Kilo Guru

Hi Phil,



Try using the Service Catalog Script API.   Example 3 shows how to set your variables.


Service Catalog Script API - ServiceNow Wiki


Jordan,


Thanks very much for your response.   I've had a quick look at your link, but can't see how this would create a new requestable catalog item.   The API seems to be used to raise a request for an existing item, but I'm trying to add a new item to the catalog.   Can you suggest how I'd incorporate that in the script?   Sorry if I'm missing something obvious.


No worries.   In your script, add this as the last line:


cat_item.insert();