0

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.

2
  • We achieved this previously with action script and web client SDK as well, is there any reason you want to achieve this with Javascript SDK? Jun 6, 2023 at 11:39
  • I am creating one react based external component which will be placed on asset detail page, it will have one simple button and clicking on this button will refresh all the renditions, as of now you can't do this on asset detail page you have to do this from asset listing page.
    – Gautam
    Jun 6, 2023 at 13:08

1 Answer 1

0

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);
      }
    }

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.