Is there any way we can refresh renditions using Javascript SDK
?
I know we can do this with triggers and action scripts
or using Web client SDK
but I need to do this with Javascript SDK
.
Is there any way we can refresh renditions using Javascript SDK
?
I know we can do this with triggers and action scripts
or using Web client SDK
but I need to do this with Javascript SDK
.
I figured it out. Below is the code snippet for refreshing the renditions through Javascript SDK.
// Create the JavaScript SDK client
const client = new ContentHubClient(endpoint, oauth);
var isAuthenticate = await client.internalClient.authenticateAsync();
console.log(isAuthenticate);
var jobEntity = null;
jobEntity = await client.entityFactory.createAsync("M.Job");
jobEntity.setPropertyValue("Job.Type", "MassEdit");
jobEntity.setPropertyValue("Job.State", "Created");
jobEntity.setPropertyValue("Job.Condition", "Pending");
jobEntity.setPropertyValue("Job.TargetCount", 0);
jobEntity.setPropertyValue("Job.TargetsCompleted", 0);
var jobId = await client.entities.saveAsync(jobEntity);
var descriptionEntity = await client.entityFactory.createAsync(
"M.JobDescription"
);
var jobConfiguration = {
$type:
"Stylelabs.M.Base.MassEdit.MassEditJobDescription, Stylelabs.M.Base",
Operations: [
{
$type:
"Stylelabs.M.Base.MassEdit.RefreshRenditionsOperation, Stylelabs.M.Base",
Renditions: [],
FailedOnly: true,
RefreshHistory: false,
RefreshSubfiles: false,
},
],
FinalizeOperations: [],
Targets: [assetId],
};
console.log(jobConfiguration);
console.log(JSON.stringify(jobConfiguration));
descriptionEntity.setPropertyValue("Job.Configuration", jobConfiguration);
var jobRel = descriptionEntity.getRelation(
"JobToJobDescription",
RelationRole.Child
);
if (jobRel != null) {
jobRel.setIds([jobId]);
var descriptionId = await client.entities.saveAsync(descriptionEntity);
console.log(descriptionId);
var loadConfig = new EntityLoadConfiguration();
loadConfig.propertyLoadOption = new PropertyLoadOption([
"Job.State",
"Job.TargetCount",
]);
loadConfig.relationLoadOption = RelationLoadOption.None;
loadConfig.cultureLoadOption = CultureLoadOption.Default;
jobEntity = await client.entities.getAsync(jobId, loadConfig);
if (jobEntity != null) {
console.log(jobEntity);
jobEntity.setPropertyValue("Job.State", "Pending");
jobEntity.setPropertyValue("Job.TargetCount", 1);
await client.entities.saveAsync(jobEntity);
}
}