Get Page type from Node object

Ivan Louw asked on August 20, 2019 00:22

Hi,

I have captured a document event on the integration bus, for when ever a page is created or updated. using public override IntegrationProcessResultEnum ProcessInternalTaskAsync(TreeNode node, TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName, out string errorMessage

But I need to get to the page type of the page as this is where the information I need is stored. Is there a way to get to the page type from the node or page object?

Thanks for any help.

Recent Answers


Juraj Ondrus answered on August 20, 2019 08:24

The page object has the NodeClassID column - this is the ID of the class from CMS_Class table - and in this particular case the class equals page type. Also, depending what API you are using, the page/node object should have the ClassName property which contains the page type code name directly.

0 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on August 20, 2019 10:11

Hi Jaraj,

Thanks for the advice. I can get the class name from the node. The problem is I have content type page type, so when a new page is created I must go and get the saved page data from the page type. To get to id I will need to use the document id, need to get foreign key and get the object for that id.

What would be the best way to a chief this?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on August 20, 2019 10:30

What API are you using? E.g. you can use document query and use DocumentHelper.GetDocuments with .WithCoupledColumns() to get all the data. Just as it is shown in our API examples

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on August 20, 2019 11:01

Hi Ivan!

You can use either strong typed Page Type objects in this method or just a GetValue of TreeNode. For example:

public override IntegrationProcessResultEnum ProcessInternalTaskAsync(TreeNode node,
    TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName,
    out string errorMessage)
{
    errorMessage = String.Empty;

    // cast to strong type
    var article = node as Article;

    // access the custom field
    var summary = article.ArticleSummary;

    // get without strong type
    var summary2 = node.GetValue("ArticleSummary");

    return IntegrationProcessResultEnum.OK;
}

Please note, that you need to have generated class for page type. In the example above you should have Article.generated.cs in your solution. And if it is MVC - you should have it in Admin Web Application as well! Hope it helps.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.