
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Building Service requests (catalogs) are an integral part of ServiceNow. While creating a holistic workflow that is able to handle the entire fulfilment process is recommended, but more often than not, you might find the need to enable ad-hoc Catalog task creation to handle an unplanned effort by another team.
Enabling the new task creation is simple but you don't get to see variable editor on such tasks that show the details which were filled on the Service request. The below solution would help you just do that.
Edit: Updated the script to query the variables of catalog directly instead of using sc_item_option_mtom for performance reasons.
Begin by creating an After-Insert business rule on Catalog task table (sc_task).
Condition: It depends on your need. You can either leave it blank or add a condition to limit it to a specific catalog request.
Script:
var questions = [];
var catalogItem = current.request_item.cat_item.toString();
var variableSets = [];
var getVariableSets = new GlideRecord('io_set_item');
getVariableSets.addQuery('sc_cat_item',catalogItem);
getVariableSets.query();
while(getVariableSets.next()) {
variableSets.push(getVariableSets.getValue('variable_set'));
}
var getCatalogVariables = new GlideRecord('item_option_new'); getCatalogVariables.addQuery('cat_item='+catalogItem+'^active=true^NQvariable_set.sys_idIN'+variableSets.toString()+'^active=true');
getCatalogVariables.query();
while(getCatalogVariables.next()) {
questions.push(getCatalogVariables.getValue('sys_id'));
}
var variablesCount = questions.length;
var currentTaskID = current.sys_id.toString();
for(var i=0;i<variablesCount;i++)
{
var getTaskVariables = new GlideRecord('sc_item_variables_task');
getTaskVariables.addQuery('task',currentTaskID);
getTaskVariables.addQuery('variable',questions[i]);
getTaskVariables.setLimit(1);
getTaskVariables.query();
if(!getTaskVariables.hasNext())
{
getTaskVariables.initialize();
getTaskVariables.setValue('task',currentTaskID);
getTaskVariables.setValue('variable',questions[i]);
getTaskVariables.insert();
}
}
sc_item_variables_task table is a near equivalent table of sc_item_option_mtom table but this is related to the catalog task (sc_task) table. Interestingly, this table just holds the reference to the variable and not the variable value. ServiceNow magic uses the information from this table and builds the variable editor on catalog tasks.
If you liked the content, please share, like, bookmark or leave your valuable comments.
- 4,298 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.