Display Multiple Catalog Items as a named link in Virtual agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 02:52 AM
Hi All,
How to display multiple link as named Catalog Item in ServiceNow Virtual agent
I have queried and got the name,sys_id,and short_description of 4 catalog items where name contains "Laptop" and have stored it in a variable.
All variables name with value display==[{"name":"Standard Laptop","sysid":"04b7e94b4f7b4200086eeed18110c7fd","short_description":"Lenovo - Carbon x1"},{"name":"Development Laptop (PC)","sysid":"3cecd2350a0a0a6a013a3a35a5e41c07","short_description":"Dell XPS 13"},{"name":"Developer Laptop (Mac)","sysid":"774906834fbb4200086eeed18110c737","short_description":"Macbook Pro"},{"name":"Sales Laptop","sysid":"e212a942c0a80165008313c59764eea1","short_description":"Acer Aspire NX"}]
I want my BOT response in such a way that, Standard laptop is the name of catalog and when clicked it should go to Portal link of that Catalog Item.
Standard Laptop
Lenovo - Carbon x1
Development Laptop (PC)
Dell XPS 13"},{"name":"Developer Laptop (Mac)
I know we can do this as a static one
But how to do it dynamic so that it enters the loop and gets the name,short_description and sys_id and
(function execute(header) {
//Return up to 3 links. For example:
var groupedLinksOutMsg = new sn_cs.GroupedPartsOutMsg();
groupedLinksOutMsg.setHeader(header);
groupedLinksOutMsg.addLinkPart('link 1 label', 'www.link1.com', 'a short desc');
groupedLinksOutMsg.addLinkPart('link 2 label', 'www.link2.com', 'a short desc');
groupedLinksOutMsg.addLinkPart('link 3 label', 'www.link3.com', 'a short desc');
return groupedLinksOutMsg;
})(header)
- Labels:
-
Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 02:30 AM
Hi Harsha,
I don't really understand what you have the problem with, but I had almost the same requirement.
The way to dynamically set the links is just a simple loop like this. You have to construct the URL for the link as well. The script in your case would be something like this:
var groupedLinksOutMsg = new sn_cs.GroupedPartsOutMsg();
groupedLinksOutMsg.setHeader(header);
var resultsObj = [{}, ... {}];//your list of cat items
for(var i = 0; i < resultsObj.length; i++) {
var url = gs.getProperty('glide.servlet.uri') + "/sp?id=sc_cat_item&sys_id=" + resultsObj[i].sysid;
groupedLinksOutMsg.addLinkPart(
resultsObj[i].name,
url,
resultsObj[i].short_description,
resultsObj[i].misc);
}
return groupedLinksOutMsg;
Where the resultsObj is the array containing the objects with 4 properties (I don't know if you can leave out the fourth or not). the link label, the link URL, a summary text and a miscellanious text (that is the small text at the bottom). Please note that you can show only 3 items at a time, this is an out of the box limitation of the bot response output. If you want to show more than 3, you have to use a HTML bot response instead.
I hope this helps,
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 12:33 PM
Hi @Harsha
First create the script variables, pic the the 'script action utility' and load the script variables like below
var result = [{"name":"Standard Laptop","sysid":"04b7e94b4f7b4200086eeed18110c7fd","short_description":"Lenovo - Carbon x1"},{"name":"Development Laptop (PC)","sysid":"3cecd2350a0a0a6a013a3a35a5e41c07","short_description":"Dell XPS 13"},{"name":"Developer Laptop (Mac)","sysid":"774906834fbb4200086eeed18110c737","short_description":"Macbook Pro"},{"name":"Sales Laptop","sysid":"e212a942c0a80165008313c59764eea1","short_description":"Acer Aspire NX"}];
(function execute(header) {
var groupedLinksOutMsg = new sn_cs.GroupedPartsOutMsg();
groupedLinksOutMsg.setHeader(header);
groupedLinksOutMsg.addLinkPart(vaVars.title1, vaVars.url1, vaVars.shortDescription);
groupedLinksOutMsg.addLinkPart(vaVars.title2, vaVars.url2, vaVars.shortDescription);
groupedLinksOutMsg.addLinkPart(vaVars.title3, vaVars.url3, vaVars.shortDescription);
return groupedLinksOutMsg;
})(header)