In the previous post, we have set up an index with computed field allowing us to query Sitecore items by referenced assetId. We can now use this to build a nice widget on Contenthub’s asset details page:

In the previous post, we have set up an index with computed field allowing us to query Sitecore items by referenced assetId. We can now use this to build a nice widget on Contenthub’s asset details page:

ContentHub integrates nicely with Sitecore XM through Sitecore Connect for ContentHub. Probably the most popular use case is referencing assets stored in ContentHub’s DAM instead of using classic Media Items. This is integrated nicely through an extension of the image field:

In some cases, authors might want to search ContentHub for a DAM asset by its ID. Out of the box, this is not possible via the search GUI but it can be enabled with a trick:


The field doesn’t need to be displayed on any pages as it will be populated automatically.

using Stylelabs.M.Sdk;
using Stylelabs.M.Sdk.Contracts.Content;
try {
long assetId = Context.TargetId.Value;
var client = MClient;
var assetToUpdate = await client.Entities.GetAsync(assetId);
// Write Asset ID to SearchableAssetId field (for search in fulltext index)
if (assetToUpdate.GetPropertyValue<string>("SearchableAssetId") != assetId.ToString()) {
MClient.Logger.Info($"Setting SearchableAssetId to: {assetId}");
assetToUpdate.SetPropertyValue("SearchableAssetId", assetId.ToString());
client.Entities.SaveAsync(assetToUpdate);
}
}
catch (Exception e) {
MClient.Logger.Info(e.ToString());
return;
}
2. Create an action that references your script

3. Create a trigger, that fires when “SearchableAssetId” is empty



In order to test, you’ll need to re-save a DAM asset. This will trigger our script asychronously and eventually update the search index. It might take a few minutes for the index to be updated.
When all is done, you should be able to search for assets by their IDs.
