Catalog item in Contextual Search Results

SamuelChang
Tera Contributor

Hello,

I enabled "cxs_EmailSearchResults" in my notification, so whenever an Incident created the caller will receive an email with the "Related Search Results" result in their email. Include knowledge articles, and catalog item. My issue is whenever the results include the catalog items, and I open from the email it only display the catalog item's description. image.png

Where as if I go to the incident and select "Order" under the "Related Search Results" it pointed directly to the catalog item itself
image.png

 

If anyone has the solution or point me to the right direction I'd greatly appreciated it!

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @SamuelChang,

 

I wasn't able to find much info on this so decided to do some testing in the PDI and found a solution.

Hopefully, you are familiar with scripting as this will require a bit of it.

 

The link generated in the email notification is created by the cxs_result_email Macro. This can be seen in the email script cxs_EmailSearchResults.

JamesChun_0-1712787503491.png

If you look at the script, the searchResponseObj is passed into the Macro as the input. If you try printing it out, it will be something like the following (I collapsed most of the response for legibility):

JamesChun_1-1712787605281.png

The 'link' value of the 'results' array is passed to the Macro which is displayed as the link in the email notification. So, looking at the above screenshot, the value of the 'link' is fine for a Knowledge article (last object in the results array) but for a Catalog Item, it's something like cxs_cat_item.do?.... which is not a link to a catalog item.

 

So, if we can modify the value of the 'link', it should fix the problem.

I was hoping if there is an easy way of configuring it (e.g. modifying some records) but wasn't able to find one.

Instead, I decided to clone and modify the Macro as the following.

You will notice that there are about 4 additional lines (line 6-9) to check if the link contains a text of 'cxs_cat_item', and if so, use the 'link' value in the 'related_links' object.

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:evaluate jelly="true">
		var title = jelly.jvar_cxs_result.title;
		var url = jelly.jvar_cxs_result.link;
		if(url.indexOf('cxs_cat_item') > -1)
		{
			url = jelly.jvar_cxs_result.related_links[0].link;
		}
		var snippet = jelly.jvar_cxs_result.snippet;
	</g:evaluate>
	<div style="margin-top: 10px;"></div>
	<div style="font-size: 10pt;font-family: Arial;color: #485563;">
		<a href="${url}" class="web kblinked" style="font-family: Arial;color: #485563;font-size: 12pt;text-decoration: underline;padding: 0px;cursor: pointer;display: block;width: 100%">
			<g:no_escape><g:highlighter search="${searchTerm}">${title}</g:highlighter></g:no_escape>
		</a>
	</div>
	<div style="font-size: 10pt;font-family: Arial;color: #485563;width:100%">${snippet}</div>
</j:jelly>

 

Once the new Macro is created, make sure you update the email script to use the new Macro instead of the OOB Macro.

i.e. "result_macro" : "your_new_macro"

 

Hope that makes sense, cheers

View solution in original post

4 REPLIES 4

James Chun
Kilo Patron

Hi @SamuelChang,

 

I wasn't able to find much info on this so decided to do some testing in the PDI and found a solution.

Hopefully, you are familiar with scripting as this will require a bit of it.

 

The link generated in the email notification is created by the cxs_result_email Macro. This can be seen in the email script cxs_EmailSearchResults.

JamesChun_0-1712787503491.png

If you look at the script, the searchResponseObj is passed into the Macro as the input. If you try printing it out, it will be something like the following (I collapsed most of the response for legibility):

JamesChun_1-1712787605281.png

The 'link' value of the 'results' array is passed to the Macro which is displayed as the link in the email notification. So, looking at the above screenshot, the value of the 'link' is fine for a Knowledge article (last object in the results array) but for a Catalog Item, it's something like cxs_cat_item.do?.... which is not a link to a catalog item.

 

So, if we can modify the value of the 'link', it should fix the problem.

I was hoping if there is an easy way of configuring it (e.g. modifying some records) but wasn't able to find one.

Instead, I decided to clone and modify the Macro as the following.

You will notice that there are about 4 additional lines (line 6-9) to check if the link contains a text of 'cxs_cat_item', and if so, use the 'link' value in the 'related_links' object.

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:evaluate jelly="true">
		var title = jelly.jvar_cxs_result.title;
		var url = jelly.jvar_cxs_result.link;
		if(url.indexOf('cxs_cat_item') > -1)
		{
			url = jelly.jvar_cxs_result.related_links[0].link;
		}
		var snippet = jelly.jvar_cxs_result.snippet;
	</g:evaluate>
	<div style="margin-top: 10px;"></div>
	<div style="font-size: 10pt;font-family: Arial;color: #485563;">
		<a href="${url}" class="web kblinked" style="font-family: Arial;color: #485563;font-size: 12pt;text-decoration: underline;padding: 0px;cursor: pointer;display: block;width: 100%">
			<g:no_escape><g:highlighter search="${searchTerm}">${title}</g:highlighter></g:no_escape>
		</a>
	</div>
	<div style="font-size: 10pt;font-family: Arial;color: #485563;width:100%">${snippet}</div>
</j:jelly>

 

Once the new Macro is created, make sure you update the email script to use the new Macro instead of the OOB Macro.

i.e. "result_macro" : "your_new_macro"

 

Hope that makes sense, cheers

Tested on my PDI and it's working as intended. Thanks a lot!

Hi James,

 

I was wondering if you knew of any way to make these links open up in the service portal instead of the back-end view? For both knowledge articles and catalog items.

 

I don't have too much experience with jelly so I'm not sure how to manipulate the URL.

 

Thanks!

I figured it out somehow.

sp_link has most of the needed URL for catalog items. Adding "sp" infront of it created the full URL needed to open a catalog item in the service portal.

 

url = "sp" + jelly.jvar_cxs_result.related_links[0].sp_link;