How to dynamically display clickable links in Bot Response coming from 3rd party?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 03:40 PM
I have integration setup, Its integration with external knowledge base. I am having issue where when we get the response back from that knowledge base Virtual agent topic is not able to display the content in the same format as in the source. Links are not coming as expected. At present I am using spit function to get the links. its only working when we have only one link embedded the response. When there are a multiply links some of words are being cut off and I can not seems to find the solution for it.
"Test is currently used for Test Accounts only. There are 3 group accounts used in RI: - Group accounts are universal across company code and are marked as Key accounts so needs to be reconciled monthly. For additional questions, please [click here](https://someurl.com/test') to submit a service request to our **TestSetup** team."
Where [click here] is not clickable but its given separate. We want those links to be clickable as they are defined in the external source in this case [click here] should be just hyperlink.
This is my script include that being used :
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(endpoint);
request.setHttpMethod('POST');
request.setRequestHeader("Authorization", endpointkey);
request.setRequestHeader("Content-Type", "application/json");
var body = {
'question': vaInputs
};
var bd = JSON.stringify(body);
request.setRequestBody(bd);
var response = request.execute();
gs.log(response.getStatusCode());
gs.log('SB '+response.getBody(), 'SB');
var parser = new JSONParser();
var parsedData = parser.parse(response.getBody());
var data = parsedData.answers[0].answer;
var info = data.split('[');
//info[0]
var str = data.split(')');
var len = str.length-1;
var tail = str[len];
var ex = data.split('[');
var keyword = [];
for (var i = 1; i <= ex.length - 1; i++) {
var getKeyword = ex[i].split(']');
// keyword = keyword + getKeyword[0] + '\n';
keyword.push(getKeyword[0].toString());
}
var getHttps = data.split('https');
var link = "https";
var getLink = '';
var links = [];
for (var j = 1; j <= getHttps.length - 1; j++) {
getLink = getHttps[j].split(')');
//links = links + link + getLink[0] + '\n';
links.push(link + getLink[0].toString());
}
var code = "";
var l = '';
for (var a = 0; a < links.length; a++) {
code = code + '<div>' + '<a href='+links[a]+' target="_blank">' + keyword[a] + '</a>' + '</div>';
}
return info[0]+' '+ code + tail;
//return info[0] + '\n'+keyword+links;
},
type: 'QnA_Maker_Utils'
Here is topic property : I am taking user input passing to API call
API link list value expression :
var resp = new global.QnA_Maker_Utils().QnAMaker(vaInputs.qna_maker.toString())
return resp;
If anyone has done anything similar please put some guidance so I can get this going thanks!
Thanks,
Shodi
- Labels:
-
Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 10:02 PM
Hi there,
You are using the Bot Response Link now? Have you considered using the Bot Response HTML? This gives you more flexibility and would for sure help you in achieving displaying multiple links.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 06:38 AM
Hey Mark,
I have tried that that unfortunately, Bot Response HTML - "The HTML bot response shows a static HTML as a chat response." There is no way of getting the out put to this activity. But if you have done something similar please let me know how I open to experiment it.
Thanks,
Shodi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 07:32 AM
Ah I see, I misread your question.
You could use a Bot Response text, and in the script return HTML. For example, I just only scripted a <a href>, which gives me a clickable link. Obviously you could have multiple links, etc. What ever you want.
Code could already be as simple as:
(function execute() {
return "<a href='https://developer.servicenow.com/blog.do'>LINK</a>";
})()
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2020 01:01 PM
Thanks for replying on this one Mark, my code is working fine when I have only one link in the response even with multiple I am able to get the links only issue is that words between the 2nd and end of 3rd links are getting cut off. For example :
"Test is currently used for Test Accounts only. There are 3 group accounts used in RI: - Group accounts are universal across company code and are marked as Key accounts so needs to be reconciled monthly. For additional questions, please [click here](https://someurl.com/test') to submit a service request to our **TestSetup** team.
Test is currently used for Test Accounts only. There are 3 group accounts used in RI: - Group accounts are universal across company code and are marked as Key accounts so needs to be reconciled monthly. For additional questions, please [click here](https://someurl.com/test') to submit a service request to our **TestSetup** team.
Test is currently used for Test Accounts only. There are 3 group accounts used in RI: - Group accounts are universal across company code and are marked as Key accounts so needs to be reconciled monthly. For additional questions, please [click here](https://someurl.com/test') to submit a service request to our **TestSetup** team."
Lets say I have above response back from external source. My Code is able to get the link clickable like so but words 2nd and end of 3rd links are getting cut off.
"Test is currently used for Test Accounts only. There are 3 group accounts used in RI: - Group accounts are universal across company code and are marked as Key accounts so needs to be reconciled monthly. For additional questions, please click here to submit a service request to our **TestSetup** team.
Test is currently used for Test Accounts only. There are 3 group accounts used in RI: - Group accounts are universal across company code and are marked as Key accounts so needs to be reconciled monthly. For additional questions, please click here
After parsing that's my end result.