The Zurich release has arrived! Interested in new features and functionalities? Click here for more

how to create request item from script

Alex_Rybalchenk
Tera Contributor

I'm trying to build a background script that will create a new request item. Since there are related tables involved, what would be the correct creation sequence, e.g. which table record should be created first to be associated with the request item record? If somebody has a working code snippet or a least an idea, I would appreciate it. Tried to find a solution in the community posts but related topics are not very descriptive.

13 REPLIES 13

Can you please let us know how we can do the same as 1B for catalog items which has Multi Variable Sets.

Mateusz13
Tera Contributor

Hello, 

I created a background script that creates new catalog item with this settings:

- set up catalog and category

-set up short description / description

- add predefine variable set (in my case 2)

- creates and connects new group that will be use as access group for new item

 

var gr = new GlideRecord("sys_user_group");

var a = "TYPE HERE"; // TYPE GROUP NAME, IT WILL BE USED TO CREATE ITEM 

gr.initialize();

gr.name = "TYPE HERE" + a; // CAN BE REMOVED IF YOU DO NOT NEED ANY TEXT BEFORE GROUP NAME

gr.company = "SYS ID OF COMPANY FIELD"; // CAN BE REMOVED IF NOT NEEDED

gr.manager = "SYS ID OF MANAGER "; // SYS ID OF USER THAT WILL BE ACCESS GROUP MANAGER

gr.description = "access group for item " + a;  // SET UP DESCRIPTION

var sys_id = gr.insert();

 

var gram2 = new GlideRecord("sc_cat_item");

gram2.initialize();

gram2.name = a; // CREATES ITEM WITH SAME NAME AS ACCESS GROUP

gram2.sc_catalogs = "TYPE HERE"; // CATLOG NAME (DOES NOT HAVE TO BE SYS ID)

gram2.category = "TYPE HERE"; // CATEGORY SYS ID

gram2.short_description = a ; // SHORT DESCRIPTION, SAME AS GROUP / ITEM NAME, CAN BE CHANGED TO ANYTHING

gram2.description = "TYPE HERE"; // ITEM DESCRIPTION

var sys_id2 = gram2.insert();

 

var gr1 = new GlideRecord("io_set_item");

gr1.initialize();

gr1.setValue('variable_set', 'TYPE HERE'); // VARIABLE SET SYS_ID

gr1.setValue('sc_cat_item', sys_id2 );

gr1.order = '200'; //YOU CAN CHANGE ORDER

gr1.insert();

 

var gr4 = new GlideRecord("io_set_item");

gr4.initialize();

gr4.setValue('variable_set', 'TYPE HERE'); // SECOND VARIABLE SET SYS ID

gr4.setValue('sc_cat_item', sys_id2 );

gr4.order = '100'; //YOU CAN CHANGE ORDER

gr4.insert();

 

var gr5 = new GlideRecord("user_criteria"); // NEW USER CRITERIA ( AVAILABLE FOR

gr5.initialize();

gr5.name = "TYPE HERE" + a; // AVAILABLE FOR RECORD NAME

gr5.group = sys_id

var sys_id = gr5.insert();

 

var gr6 = new GlideRecord("sc_cat_item_user_criteria_mtom"); // ADDS ACCESS GROUP TO ABOVE RECORD)

gr6.initialize();

gr6.setValue('user_criteria', sys_id );

gr6.setValue('sc_cat_item', sys_id2 );

gr6.insert();

Prasanna24
Kilo Contributor
Hi Alex have u achieved this.... I have a similar requirement to create a RITM THROUGH WORKFLOW SCRIPT

kishorek1
Tera Contributor
   var request = new GlideRecord('sc_request');

   request.initialize();

   request.setValue('short_description', current.short_description);
   request.setValue('description', current.description);
   request.setValue('requested_for', current.caller_id);



   request.insert();