How to get current DocumentNamePath of an un-linked child node of a linked parent node?

Binod Paikaray asked on October 26, 2017 17:23

Hello,

We've a node hierarchy like parent node is a linked node and it has some child nodes from which few are linked and few are unlinked.

Is there any way to get the DocumentNamePath of the current tree and not of the linked node tree?

Thanks,

Binod Paikaray

Recent Answers


Matt Nield answered on October 27, 2017 02:17

You can get the DocumentNamePath of the original node by examining the original node as follows in code-behind:

var doc = DocumentHelper.GetDocument(CurrentDocument.NodeLinkedNodeID, new TreeProvider());
var originalDocumentNamePath = doc.DocumentNamePath;

If you want to use this in a macro, you can try:

{% CurrentDocument.NodeLinkedNode.Documents[0].DocumentNamePath #%}

If you're looking to create a link to the document, in some cases you can just use CurrentDocument.NodeAliasPath as a the relative URL.

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on October 27, 2017 14:17

Thanks to all for your responses!

Actually, my problem is with the linked nodes DocumentNamePath in the REST response. I have a linked node which has some child nodes among which few are linked and few are not. For the linked child node, it's showing it's original node's DocumentNamePath which is fine but for the un-linked child nodes also it's showing that linked node DocumentNamePath as it's parent is a linked node.

We want to get the current hierarchy's path as the DocumentNamePath.

Below, I'm trying to explain it with an example.

A --> B (Linked node may be some X --> Y)
      |--> C (Linked Node say M --> N)
      |--> D (Not linked to any node)

where A is the parent of B and B is the parent of C and D.

Now, the DocumentNamePath for:

B is X --> Y --> B

C is M --> N --> C

D is X --> Y --> B --> D

But for D, we want it as

A --> B --> D in the REST response itself as some other application is consuming the data from there.

I hope, my requirement is clear now.

Please help me to accomplish this task.

Thanks,

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 27, 2017 15:12

Hi Binod, yes, I see what you're trying ot do here. The short answer is that I don't think that the out-of-the-box REST API is going to behave the way that you want. For content, the API is focussed on the CMS_Tree structure, and your linked document effectively is a new item in here. Your calling service may need to do some work here by calling the API again when NodeLinkedNodeID is not null.

For example, on my test site, when I call http://localhost/cx10/rest/content/site/blank/en-GB/all?classnames=cms.news&columns=nodealiaspath,DocumentName,DocumentNamePath,NodeAliasPath,NodeLinkedNodeID

I see the following results:

<cms_documents>
    <cms_news>
        <nodealiaspath>/News/News-article-1</nodealiaspath>
        <DocumentName>News article 1</DocumentName>
        <DocumentNamePath>/News/News article 1</DocumentNamePath>
    </cms_news>
    <cms_news>
        <nodealiaspath>/News/News-article-2</nodealiaspath>
        <DocumentName>News article 2</DocumentName>
        <DocumentNamePath>/News/News article 2</DocumentNamePath>
    </cms_news>
    <cms_news>
        <nodealiaspath>/News/News-article-3</nodealiaspath>
        <DocumentName>News article 3</DocumentName>
        <DocumentNamePath>/News/News article 3</DocumentNamePath>
    </cms_news>
    <cms_news>
        <nodealiaspath>/News/News-article-4</nodealiaspath>
        <DocumentName>News article 4</DocumentName>
        <DocumentNamePath>/News/News article 4</DocumentNamePath>
    </cms_news>
    <cms_news>
        <nodealiaspath>/News/News-article-5</nodealiaspath>
        <DocumentName>News article 5</DocumentName>
        <DocumentNamePath>/News/News article 5</DocumentNamePath>
    </cms_news>
    <cms_news>
        <nodealiaspath>/Home/News-article-1</nodealiaspath>
        <DocumentName>News article 1</DocumentName>
        <DocumentNamePath>/News/News article 1</DocumentNamePath>
        <NodeLinkedNodeID>1384</NodeLinkedNodeID>
    </cms_news>
</cms_documents>

The last item in the list here is a linked document, so I know I need to retrieve it using http://localhost/cx10/rest/content/site/blank/en-GB/all?classnames=cms.news&columns=nodealiaspath,DocumentName,DocumentNamePath,NodeAliasPath,NodeLinkedNodeID&where=NodeID=1384

If you need something more tailored than that, it's my understanding that you're going to create something custom.

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on October 27, 2017 15:33 (last edited on October 27, 2017 15:38)

Thanks very much Matt!

I got your answer and currently we are doing same for the linked nodes but as I mentioned in the example tree structure, for the unlinked child node of a linked parent node, this NodeLinkedNodeID is not available at all and so for all the normal nodes which are not linked to any node.

So, if NodeLinkedNodeID is available, we can do something for those type of nodes but when this field is not available then how to perform some action for those (un-linked child node of a linked parent node)?

Even if I create a new service, don't you think I would need to call it for all the documents which can be a very tedious and costly task.

Thanks,

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 27, 2017 15:56

If you create a new service, then you'll have more control over what you're doing. Yes, it's probably going to be costly unless you can put this together in SQL and use that query to drive your new service.

0 votesVote for this answer Mark as a Correct answer

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