Update Asset Description for Sitecore Content Hub

Ana Sayfa Blog Update Asset Description for Sitecore Content Hub

Update Asset Description for Sitecore Content Hub

Sample C Sharp code I've written for updating Asset Description for Sitecore Content Hub.

You can use it as you like, you may even change and develop your own code.

using System.Globalization;

long assetId = -1;
IEntity thisAsset = null;
string assetTitle = null;
string assetFileName = null;
string assetDescription = null;
string updatedDescription = null;
CultureInfo culture = new CultureInfo("en-US", false);

try
{
    MClient.Logger.Info($"Begin script run...");
    long? tempId = Context.TargetId;

    if(tempId.HasValue)
    {
        assetId = tempId.Value;
        MClient.Logger.Info($"The Asset Id is {assetId}");

        thisAsset = await MClient.Entities.GetAsync(assetId);

        MClient.Logger.Info($"

The Asset Identifier is {thisAsset.Identifier}, and entity definition name is {thisAsset.DefinitionName}

"); assetTitle = thisAsset.GetPropertyValue("Title"); assetFileName = thisAsset.GetPropertyValue("FileName"); updatedDescription = $"The asset title is {assetTitle}, and file name is {assetFileName}."; MClient.Logger.Info(updatedDescription); thisAsset.SetPropertyValue("Description", culture, updatedDescription); await MClient.Entities.SaveAsync(thisAsset); } else { MClient.Logger.Info($"The TargetId is null, exiting."); throw new Exception("Null value exception, No TargetId in the Context"); } } catch (Exception e) { MClient.Logger.Error($"{e.Message}"); }

Sinan Eldem

Fullstack Web Developer

Laravel Framework ile PHP ve MySQL üzerine özel ders, danışmanlık ve web programcılığı hizmetleri veriyorum.

Danışmak istedikleriniz ile ilgili benimle irtibat kurabilirsiniz.

Yorumlar