Content Hub Tip #22: Change LifeCycle status of an Asset via Web SDK

 

Content Hub Tip logo

Sometimes you want to do something simple and end up overcomplicating things. It happened to me a while back when I wanted to automatically approve a draft asset by a given date via script. I first tried to manually update the LifeCycleStatus by hand. Although this works, it's not what you should do. There is a better and easier way to achieve this. Because a draft asset not only needs to be approved it also needs to be merged with the original asset. Thomas of Sitecore showed me a better method to do this.

When we take a closer look at the IMClient interface it also has an Assets property. This property exposes the IAssetsClient interface. This gives us access to the IFinalLifeCycleManager interface, hang in there, we're almost there. 

This interface allows us to do some cool actions on an asset, like archiving, approving, publishing, rejecting, restoring and submitting. So basically everything we need to do ;). The only thing it needs is the ID of an asset.

const long assetId = 30001;

await mClient.Assets.FinalLifeCycleManager.ArchiveAsync(assetId);
await mClient.Assets.FinalLifeCycleManager.ApproveAsync(assetId);
await mClient.Assets.FinalLifeCycleManager.DirectPublishAsync(assetId);
await mClient.Assets.FinalLifeCycleManager.RejectAsync(assetId);
await mClient.Assets.FinalLifeCycleManager.RestoreAsync(assetId);
await mClient.Assets.FinalLifeCycleManager.SubmitAsync(assetId);

So you now know how to easily change the status of an asset. 

Happy coding' and until next time!