How to pass URLs in catalog OnLoad script in showFieldMsg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 10:18 PM
hi Developers,
I want to pass the URL links from backend table to the catalog form in showFieldMsg.
I am able to get it in array till script include, but unable to show it in catalog script.
Kindly help me with the script, also the links should be in clickable format in new tab.
Script include :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 11:05 PM
Hello @Shwetha Nair ,
Please try to use below updated scripts and see how it works for you.
Updated Script Include:
var LinksDisplay = Class.create();
LinksDisplay.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getdisplayLinkName: function() {
var arr = [];
var grurl = new GlideRecord('u_links');
grurl.addEncodedQuery("u_link_urlISNOTEMPTY");
grurl.query();
while (grurl.next()) {
arr.push(grurl.getValue("u_link_url"));
}
// Return the links as a comma-separated string
return arr.join(",");
},
type: 'LinksDisplay'
});
Updated Client Script:
function onLoad() {
var getData = new GlideAjax('LinksDisplay');
getData.addParam('sysparm_name', 'getdisplayLinkName');
getData.getXML(helloLinkParse);
}
function helloLinkParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var tlist = answer.split(",");
// Create the HTML string for clickable links
var message = '<div class="fieldmsg-container" aria-live="polite"><div class="fieldmsg notification notification-info">';
for (var i = 0; i < tlist.length; i++) {
if (tlist[i]) {
message += '<a href="' + tlist[i] + '" target="_blank">' + tlist[i] + '</a><br/>';
}
}
message += '</div></div>';
// Use g_form.showFieldMsg to show a placeholder message
g_form.showFieldMsg('u_links', 'Loading links...', 'info', false);
// Update the field message container with HTML content
var fieldMsgContainer = gel('variable.u_links_fieldmsg'); // Replace 'variable.u_links' with your actual field name if different
if (fieldMsgContainer) {
fieldMsgContainer.innerHTML = message;
}
}
Feel free to refer to the link below, which provides additional helpful information on showFieldMsg
usage and customizations.
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 11:54 PM
Thanks for your response. Few questions as I am not aware of HTML much:
1. What is exactly i need to put in variable.u_links_fieldmsg? My field name is 'u_links' and label is Links.
var fieldMsgContainer = gel('variable.u_links_fieldmsg');
2. Do i need to put the HTML part somehwere else or in OnLoad client catalog client script itself?
3. Also, I am getting this error . Would it be an issue
Thanks,
Shwetha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 11:15 PM
Your code seems correct, try to add .toString() in the return statement in script include.
return arr[i].toString();
Even better, if you can use JSON as an alternative
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 11:55 PM
hi @Deepak Negi ,
I do not want to put tostring() s I am looking to make it in clickable format.
Thanks,
Shwetha Nair