Changing the default attachment behavior in AI Search
The default behavior for attachments in AI Search is to provide them as separate search results. Additionally, the behavior is to download the attachment on click and provide a separate link for navigating to the parent record.
If you would like to remove attachments from search results, you can set the flag on the AI Search > Indexed Sources > (the name of your table) > Advanced Configuration (related list) > index_attachments. You can edit the attribute by clicking on the ‘i’.
The set the value to false.
If you would like to change the default click behavior, you will need to edit the EVAM configuration for attachments. This will change the behavior for all attachments in the system, regardless of source or portal.
First, navigate to the Attachment Search Template. Entity View Action Mapper > View Templates and search for attachment. We need to swap the clickAction and the footerLinkAction as shown here:
{
"component": "sn-search-result-evam-card",
"staticValues": {
"detailLabelType": {
"translatable": false,
"key": "inline"
},
"textHeaderLabelOne": {
"translatable": true,
"key": "Attachment"
},
"detailLabelOne": {
"translatable": true,
"key": "From:"
}
},
"mappings": {
"imageType": "doctype_image_type",
"icon": "doctype_image",
"imageURL":"doctype_image",
"textHeaderLabelTwo": "doctype",
"title": "ai_search_teaser_title",
"summary": "ai_search_teaser_text",
"detailValueOne":"parent_title",
"ariaLabel": "file_name"
},
"actionMappings": {
"clickAction": "navigation_to_parent_record",
"footerLinkAction": "navigation"
}
}
Next, we need to change the URL text for navigation, which will now act as a direct download of the attachment. We need to go to the specific navigation action for attachments, which will take a few steps.
First, navigate to the configuration associated with our template. That will be under Entity View Action Mapper > View Configurations > search for attachment. It will be listed as Attachment Search Results. Scroll to the bottom of the page to find the two actions associated with attachments.
Click on the ‘i’ next to navigation and open the record. On the next screen, click on the ‘i’ next to the Declarative Action and open that record.
Here, we can change the Action Label. I’ve changed mine to ‘Download’.
Once this has been saved our attachments will now default to opening the parent article and the download link is presented below, like this:
https://www.servicenow.com/community/intelligence-ml-articles/changing-the-default-attachment-behavior-in-ai-search/ta-p/2307619