Create catalog Item request using REST API

Kiran Patil3
Giga Expert

Hi,

I am trying to create catalog request using OOB service catalog REST API:

Here is the Request Body: all 3 variables are reference field.

find_real_file.png

Request submitted successfully but variables in RITM does not have any value.

All variables are reference but we cannot ask external system to pass sys_id. Also, display flag is true on those reference table and same value is passed through Rest API.

find_real_file.png

 

Anyone faced this issue before. Thank you so much in advance.

 

 

 

Thank You

Kiran Patil

 

 

1 ACCEPTED SOLUTION

Kiran Patil3
Giga Expert

Hi All,

Finally, I had to add small utility which can handle reference variables in REST API request for all catalog Items.

Here is script Include to run for BG:

var  variables = {"user":"Abraham Lincoln","company":"Yahoo!","comments":"This is testing Text","requested_for":"System Administrator","needed_by":"Today"};
var itemId = "b5c3c1084f10330005ec00fe9310c7eb";    //myTestItem Catalog item

    for(var key in variables)
    {
        if(variables.hasOwnProperty(key) && variables[key] && typeof(variables[key]) !== 'string')
        variables[key]=variables[key].toString();
    
        var varGr = new GlideRecord('item_option_new');
    var qr = varGr.addQuery('cat_item', itemId);
    var variableSet = new sn_sc.CatItem(itemId).getVariableSet();
    if(variableSet.length > 0)
        qr.addOrCondition("variable_set", variableSet);
    varGr.addActiveQuery();
   // varGr.addQuery('mandatory', true);
    varGr.query();
   // gs.print(variable[key] + ':' + varGr.reference);
    while(varGr.next()) {
        if(varGr.type == 8)
        {
            var objTable = new TableUtils(varGr.reference);
            tableName = objTable.getAbsoluteBase();
            gs.print(objTable.getAbsoluteBase());
            if (tableName!='task')        //Check if parent table is task
                gQuery = 'name='+variables[key]; else gQuery = 'number='+variables[key];
            var tb = new GlideRecord(tableName);
            gs.print(varGr.reference);
            tb.addQuery(gQuery);
            tb.query();
            if(tb.next())
            {
                variables[key]=tb.getValue('sys_id');
            }
        }else { variables[key]=variables[key]; }
    }
}gs.print(JSON.stringify(variables));

View solution in original post

7 REPLIES 7

manish64
Giga Guru

try to give sysid of values 

Please, remember to mark Correct or Helpful if you find my response useful.

It works with sys_id but we cannot ask external systems to send sys_id and we want to keep this generic catalog API where variables might change per catalog item.

I am checking for some generic approach.

 

Thank You

Harsh Vardhan
Giga Patron

are you using service catalog API or cart API here ?

 

Service Catalog API

 

example

Yes, I am using order_now OOB catalog API.