- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2019 11:25 PM
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.
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.
Anyone faced this issue before. Thank you so much in advance.
Thank You
Kiran Patil
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2019 06:13 PM
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2019 06:13 PM
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2020 03:59 AM
Hi,
Is this the script that you are putting in the REST Api script area?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 06:28 AM
Hi Kiran,
We have a similar requirement as yours. we have separate network request catalog item and workflow in service now it will create only request and Request Item. so requirement here is need to integrate with web application so whenever user submits the web application form it should auto create network request item with request and request item ticket and what ever the values submitted in web form should replicate in variable section of the network request item ticket. As i am new to this rest call, Could you please guide me how to achieve this requirement.
thanks in Advance.