List Field Names of a Catalog Item

Raj64
Tera Guru

Hello,

 

If I know the sys_id of a Catalog Item (sc_cat_item table), how can I list all the fields of that item using a script?

 

Many of our service request forms are incompatible with Virtual Agent. What I want to do is create topics that can help users to fill out a form. They would select a field name they need help with, then VA would give them (hard coded) instructions on how to fill out that field.

 

Thanks.

4 REPLIES 4

Sumanth16
Kilo Patron

Hi  ,

 

Please refer to below thread:

https://www.servicenow.com/community/now-platform-blog/get-all-variables-for-a-given-catalog-item/ba...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Below will list all the variables for the catalog item

var gr = new GlideRecord('item_option_new');
gr.addEncodedQuery('cat_item=<cat item sys_id>^');
gr.query();
while(gr.next())
{
//do whatever
}
-Anurag

Shaqeel
Mega Sage

Hi @Raj64 

 

You could use the GlideRecord API to query the sc_cat_item table and get all the fields of a specific Catalog Item.

var sys_id = 'your_sys_id_here'; // replace with your sys_id
var gr = new GlideRecord('sc_cat_item');
if (gr.get(sys_id)) {
var allFields = gr.getFields();
while (allFields.hasNext()) {
var field = allFields.next();
gs.info(field.getName() + ' = ' + gr.getValue(field.getName()));
}
}

 

Mark Helpful/Solution 🙂

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

Thanks Shaqeel, but I'm using a scoped application and getFields() doesn't work in scoped apps. 😞