- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-18-2020 08:54 AM
Hi there,
I recently saw a requirement that I thought would be an interesting and potentially quite useful one to develop.
The requirement was to automatically fill a variable in an Incident record producer with the users search term to save them time in rekeying. This solution would work for any record producer you apply it to.
To begin with you will need to add the search term to the URL when you open a catalog item on the sc_cat_item page, or whatever page you use to view catalog items in your portal. To do this you need to modify the portal search source which you use to display results from the catalog. I will use the OOTB Catalogs search source, which is linked to the /sp portal, as the example. Between line 48 and 61 you will see that the URL value of the item object is set.
if (item.type == "sc") {
item.url = '?id=' + item.page + '&sys_id=' + item.sys_id + '&search_term=' + query;
item.default_icon = "folder-open-o";
} else if (item.type == "sc_content") {
item.default_icon = "book";
if (item.content_type == "kb") {
item.url = '?id=kb_article&sys_id=' + item.kb_article;
item.default_icon = "file-text-o";
} else if (item.content_type == "external") {
item.url = item.url + "";
item.target = '_blank';
} else
item.url = '?id=sc_cat_item&sys_id=' + item.sys_id;
}
Set the item.url value in the if (item.type == 'sc') condition to include search_term and set that to the query.
item.url = '?id=' + item.page + '&sys_id=' + item.sys_id + '&search_term=' + query;
Next we will need to create an onLoad Catalog Client Script to set the value of a variable to this parameter. This is a very simple script that creates a URL object to easily get the value of the parameter.
function onLoad() {
//Type appropriate comment here, and begin script below
var url = new URL(this.location.href);
var c = url.searchParams.get("search_term");
g_form.setValue('comments', c);
}
Below is a demonstration of the functionality.
If you have any questions or suggestions for improvements, let me know.
Thanks,
Jack
- 1,487 Views