1

I have created some custom renditions for assets in Content Hub,so whenever i upload new asset these renditions will be created automatically, but for existing assets we need to click on refresh rendering button/link for that(to create new renditions).

Is there any way that we can write some action script which will be called from some trigger on asset modification and start a job and create these new renditions?

Thanks

1 Answer 1

-3

Got an awesome blog, You can take the reference from that

https://www.contenthub.dev/2022/10/content-hub-tip-27-refresh-renditions.html

Updating my answer as above blog is not working anymore and because of that reason I already got 3 down votes

Update : Attaching the code snippet::

var targetIds = new List<long>
{
    32637
    // use a query to get your ids
};

var jobEntity = await client.EntityFactory.CreateAsync("M.Job").ConfigureAwait(false);
jobEntity.SetPropertyValue("Job.Type", "MassEdit");        
jobEntity.SetPropertyValue("Job.State", "Created");       
jobEntity.SetPropertyValue("Job.Condition", "Pending");       
jobEntity.SetPropertyValue("Job.TargetCount", Convert.ToInt64(0));       
jobEntity.SetPropertyValue("Job.TargetsCompleted", Convert.ToInt64(0));       
var jobId = await client.Entities.SaveAsync(jobEntity).ConfigureAwait(false);       

// then the description
var descriptionEntity = await client.EntityFactory.CreateAsync("M.JobDescription").ConfigureAwait(false);  
     
string jobConfiguration = $@"{{
           ""$type"": ""Stylelabs.M.Base.MassEdit.MassEditJobDescription, Stylelabs.M.Base"",
    ""Operations"": [
        {{
            ""$type"": ""Stylelabs.M.Base.MassEdit.RefreshRenditionsOperation, Stylelabs.M.Base"",
            ""Renditions"": [{string.Join(",", renditionNames.Select(name => $"\"{name}\""))}],
            ""FailedOnly"": false,
            ""RefreshHistory"": false,
            ""RefreshSubfiles"": false
        }}
    ],
    ""FinalizeOperations"": [],
    ""Targets"": [{string.Join(",", targetIds)}]
}}";       
    

descriptionEntity.SetPropertyValue("Job.Configuration", JToken.Parse(jobConfiguration));       

var jobRel = descriptionEntity.GetRelation("JobToJobDescription", RelationRole.Child);       
jobRel.SetIds(new long[] { jobId });              
var descriptionId = await client.Entities.SaveAsync(descriptionEntity).ConfigureAwait(false);              

// logger.LogInformation($"Created job description {descriptionId}");       

// And finally update the job (we can only do that after the description is created)           

var loadConfig = new EntityLoadConfiguration()        
{        
    PropertyLoadOption = new PropertyLoadOption("Job.State", "Job.TargetCount"),
    RelationLoadOption = RelationLoadOption.None,
    CultureLoadOption = CultureLoadOption.Default       
};         
jobEntity = await client.Entities.GetAsync(jobId, loadConfig).ConfigureAwait(false);       
jobEntity.SetPropertyValue("Job.State", "Pending");       
jobEntity.SetPropertyValue("Job.TargetCount", Convert.ToInt64(targetIds.Count));       

await client.Entities.SaveAsync(jobEntity).ConfigureAwait(false);  

 
5
  • Add content from blog here as well, because this blog may not work sometimes. Oct 21, 2022 at 5:53
  • Hi Gautam, this is a link only answer. To better serve this community, can you please add a more complete answer. Oct 21, 2022 at 21:05
  • Updated my answer to serve better this community -Thank!
    – Gautam
    Jun 22, 2023 at 13:20
  • Answer is still not clear where to add the code and how to execute it. Mar 5 at 10:13
  • @JumpingRabbit , The question itself specifies that it will be written in the action script and will be called through triggers.
    – Gautam
    Mar 6 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.