The CreatorCon Call for Content is officially open! Get started here.

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

Hi @Ramya SL  ,

 

Please use below code for your reference to get all variables of the Requested Item and modify it according to your need.

 

var infoVar = new GlideRecord('sc_item_option_mtom');
    infoVar.addQuery('request_item', current.sys_id);
    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.print(question + '  ' + value);

    }
 
Also, please refer below community post.
Hope it will help.
 
Thanks
Himani

Ramya SL
Tera Contributor

Hi,

Now I actually wants to fetch particular field value of a variable name called 'Start Date' and 'Description'
Basically whenever a new user is added to the list we are passing the user is through description feild. So I need to fetch only the user Id value that is present in description.


How can modify your script to fetch only these user id present in description field values and start date field value from all the tickets of catalog item

FYR: I am using the below script for adding the user to the list

How can we fetch a particular field value with the help of above script.

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);

}