- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 12:26 PM
I'm using POST https://<instance_name>/api/sn_sc/servicecatalog/items/{sys_id}/order_now
and receiving Error Code: 400 with description saying required variable is missing.
There are mandatory variables [set by dictionary] inside a ‘variable set’ named i2_common_take.
This variable set is shared among many catalog items.
In this case, the variables that are mandatory are not visible on intake and set to non mandatory by a catalog client script and client side UI policies.
It seems like the REST API doesn’t know about or care about the concept of catalog client scripts and only looks at that fact its initially set to mandatory by the systems dictionary.
I’m able to successfully order the item if I pass in dummy values, but we cannot pass in dummy variables in this case.
Is there a method for the REST API to ignore specific mandatory variables or to set them non mandatory when ordering them?
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 01:27 PM
That is correct. When you go in to the actual method in the scripted rest api, it calls a script include RestCatalogUtil and it does checks for all the varaibles that are marked mandatory. Here is the code of it. You can customize it according to your needs, but I would recommend to stay out of box
checkMandatoryVariables: function(itemId, variables) {
variables = variables || {};
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();
while(varGr.next()) {
if((varGr.type == 7 && variables[varGr.getValue('name')] != 'true') || !variables[varGr.getValue('name')])
return false;
}
return true;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2018 01:27 PM
That is correct. When you go in to the actual method in the scripted rest api, it calls a script include RestCatalogUtil and it does checks for all the varaibles that are marked mandatory. Here is the code of it. You can customize it according to your needs, but I would recommend to stay out of box
checkMandatoryVariables: function(itemId, variables) {
variables = variables || {};
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();
while(varGr.next()) {
if((varGr.type == 7 && variables[varGr.getValue('name')] != 'true') || !variables[varGr.getValue('name')])
return false;
}
return true;
}