2

I am writing a script for one of my requirements in Sitecore Content Hub using Scripting SDK clients.

For Example: I have the following content types

  1. M.ContentType.Blog
  2. M.ContentType.News
  3. M.ContentType.Articles

On the Save button click, I am executing the Action script in which I am to find the Identifier of the content Entity.

Using the Web Client SDK I can find it by:

var identifier = ((EntityBase)entity).Identifier;

that returns M.ContentType.Blog, is there any approach to get the same in Scripting SDK?

1 Answer 1

2

You can read the Content Type from the Content in the scripting SDK using below code snippet, inside the Action script.

var contentEntity = Context.Entity;
var contentTypeId = contentEntity.GetRelation<IChildToOneParentRelation>("ContentTypeToContent").GetId();
var contentTypeEntity = await MClient.Entities.GetAsync(contentTypeId.Value);
var contentTypeEntityIdentifier = contentTypeEntity.Identifier;

Above snippet reads the relation ContentTypeToContent from Content using type IChildToOneParentRelation, since Content entity is the child for Content Type taxonomy and can have max one content type.

Hope this helps!!! Let me know in case you have any queries.

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.