- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 01:10 AM
I'm using the below script to get the catalog items based on the conditions, but it is getting errors when I run the script in the background script. Can anyone help me in script correction
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 02:16 AM
This is a good start, but on the sc_cat_item_guide_items table the field name for the order guide is 'guide' not 'sc_cat_item_guide' and the catalog item is 'item' not 'sc_cat_item', so this script will work in background:
var answer = false;
var orderGuideSysId = 'b8920108db301010a918196c29961914'; //sys_id of the order guide
var itemSysIds = [];
var grItems = new GlideRecord('sc_cat_item_guide_items');
grItems.addQuery('guide', orderGuideSysId);
grItems.query();
while (grItems.next()) {
if (grItems.item) {
itemSysIds.push(grItems.item.toString());
}
}
if (itemSysIds.length > 0) {
var grScReqItem = new GlideRecord('sc_req_item');
var itemQuery = "cat_itemIN" + itemSysIds.join(',');
grScReqItem.addEncodedQuery(itemQuery + "^stateNOT IN3,4,7");
grScReqItem.orderByDesc('assignment_group');
grScReqItem.query();
if (grScReqItem.next()) {
answer = true;
} else {
answer = false;
}
} else {
answer = false;
}
gs.print(answer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 02:16 AM
This is a good start, but on the sc_cat_item_guide_items table the field name for the order guide is 'guide' not 'sc_cat_item_guide' and the catalog item is 'item' not 'sc_cat_item', so this script will work in background:
var answer = false;
var orderGuideSysId = 'b8920108db301010a918196c29961914'; //sys_id of the order guide
var itemSysIds = [];
var grItems = new GlideRecord('sc_cat_item_guide_items');
grItems.addQuery('guide', orderGuideSysId);
grItems.query();
while (grItems.next()) {
if (grItems.item) {
itemSysIds.push(grItems.item.toString());
}
}
if (itemSysIds.length > 0) {
var grScReqItem = new GlideRecord('sc_req_item');
var itemQuery = "cat_itemIN" + itemSysIds.join(',');
grScReqItem.addEncodedQuery(itemQuery + "^stateNOT IN3,4,7");
grScReqItem.orderByDesc('assignment_group');
grScReqItem.query();
if (grScReqItem.next()) {
answer = true;
} else {
answer = false;
}
} else {
answer = false;
}
gs.print(answer);