Fetch the ticket details of a catalog item

Ramya SL
Tera Contributor

Hi All,

 

I'm new to ServiceNow. I have a requirement creating new user onboarding via catalog item. I achieved that through workflow.

 

Now I need to fetch all the ticket created for this catalog item by fetching all its variables and its values. Can anyone help me with the code to fetch all the ticket details of a  particular catalog item variable and its values present in it.

1 ACCEPTED SOLUTION

Hi,

 

Please try to use below

 

var infoVar = new GlideRecord('sc_item_option_mtom');
infoVar.addQuery('request_item.cat_item', 'use sysID of catalog Item here');
infoVar.addQuery('sc_item_option.item_option_new', 'use sysID of Description Variable here').addOrCondition('sc_item_option.item_option_new', 'use sysID of Start Date variable here');
infoVar.orderBy('sc_item_option.order');
infoVar.query();
while (infoVar.next()) {

    var question = infoVar.sc_item_option.item_option_new.getDisplayValue();
    var value = infoVar.sc_item_option.value;
    gs.info(question + '  ' + value);

}

View solution in original post

7 REPLIES 7

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Ramya SL  ,

 

You can access the varaibles used in your catalog item from table below :


Request Item to Variable: sc_item_option_mtom
Variable: sc_item_option

 

You can do a gliderecord on this table with appropriate query conditons to get all the varaibles of your catalog. We are unware of your catalog and its variables hence script cant be provided. I hope this helps...

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

My Catalog item name "New User Onboarding" and its variables
first_name,
last_name,
user_id
department
start_date
ticket_status

description

Is the below code is correct for fetching the variable names and its values of a catalog item. Please help

 


var now_GR = new GlideRecord('sc_req_item');
if (now_GR.get('sc_item_option')) {
var variables = now_GR.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion(); //getQuestion() is to fetch the variable names in ci
gs.log(question.getLabel() + ":" + question.getValue())// getLable() is variable names and getValue() is variable values
}
}


Ramya SL
Tera Contributor

Is the below code is correct for fetching the variable names and its values of a catalog item. Please help

 


var now_GR = new GlideRecord('sc_req_item');
if (now_GR.get('sc_item_option')) {
var variables = now_GR.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion(); //getQuestion() is to fetch the variable names in ci
gs.log(question.getLabel() + ":" + question.getValue())// getLable() is variable names and getValue() is variable values
}
}