How to get field (data) from another documenty type using NodeID

Dcode warner asked on March 13, 2017 19:21

I have a transformation (ASCX). I'll like to get the Column name [FirstName] (field name/data) from another page. I think the best way is through the NODE Id of that page [32697]. How can I write this?

 <%# Eval("32697.FirstName") %>

Recent Answers


Peter Mogilnitski answered on March 13, 2017 19:37

How are these two connected to each other? Related documents? Where this NodeID is coming from?

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 13, 2017 20:05 (last edited on March 13, 2017 20:07)

@Peter M The script is in the repeater and instead of targeting the current document type. I was hoping I can target another document type. Maybe NODEId isn't the best solution. But I want to grab the data from any page at any level

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on March 13, 2017 20:13

I can see a case for this, e.g. you want to display a list of Blogs and display the author's (another page type) name for it. I think Peter was asking, how are you going to associate these two together? There are multiple ways, although repeater within a repeater is not the best option, which you may want to consider create a custom query to join the two page types and get data.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 13, 2017 20:13

Not quite sure about your scenario, if you would describe the whole picture. It is hard for us to guess here. If you tend to use the repeater - use repeater with customer query Do all necessary joins in SQL, minimize number of returning columns and you good to go.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 13, 2017 20:25 (last edited on March 13, 2017 20:25)

Okay, I try to explain better:

CMS Desk > Create New Document Types (profile page)

Document Name: Profile Page 1
(field) FirstName
Document Name: Profile Page 2
(field) FirstName <!---Display FirstName from this page only

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on March 13, 2017 20:40

What you said above didn't help at all. But base on your previous questions, I assume this is related to the Blog question you have (http://devnet.kentico.com/questions/author-information-for-blog)

If you have a page type for the authors, then for your blog you can select one of the author pages based on a page selection field. Then you have the relationship between the two. Then our suggestion above of create a custom query between the blog and the author table would be the best way to get the name and bio from authors table and display on the blog page.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 13, 2017 20:59

It doesn't necessarily has to be related to a blog. Are you saying that I can't pull a field name from a document type and insert it into my transformation. Similar to this:

<%# EvalText("Parent.DocumentName") %>
0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 13, 2017 21:10

You don't need a transformation or repeater if you want to show information on you page from "Form" Tab. Use macros! Assuming you have created a document of document type "profile page" with the name "Profile Page 1" Add static text web part and put macro {%FieldName%} in your case {%FirstName%}

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 13, 2017 21:16

No. I need to use a transformation. I need to target the field of a different document type of a different page to show on a current page.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 13, 2017 22:40

Easiest way to do this (not saying its the most efficient) is to use the DocumentHelper.GetDocument() class. You have to pass a nodeid, culture string and a treeNode.

You could also switch to a Text transformation and use Documents["/node/alias/path/from/pagetype/field"].WithAllData().GetValue("ColumnName"). Again, neither are the most efficient, especially if you are doing this on each page load for a list of items.

I'm not sure what you're attempting to do but it might be worthwhile to look at another solution vs. what you're currently doing. Maybe explain the setup more in detail and can help with the overall solution using something more out of the box.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on March 13, 2017 22:42

Brenden,

He has to do in custom query (repeater with custom query) otherwise it is a query on each iteration of his repeater.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 13, 2017 22:46

Exactly Peter, he is storing that data in the page type for another page, for each page he is displaying so it will iterate through each item no matter what. So now it's a preference if he uses a nested repeater or an API query like I provided above, both will work, less overhead with a nested repeater.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 13, 2017 22:47

Okay. using this horrible code below. I'm basically trying to say if the 'Document Owner' matches.Then go and grab the field from another document.

<%# IfCompare(Eval("NodeOwnerFullName"),"Dawson Warner","No","" + Eval("NodeID(32703).Position") + "") %>

[screenshot] http://prntscr.com/ejladc

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 14, 2017 03:06 (last edited on December 10, 2019 02:30)

This won't work for me either. Even inside a Macro

{%Documents.WithAllData[NodeAliasPath].GetValue("custom_field")|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 14, 2017 15:04 (last edited on December 10, 2019 02:30)

This won't work for me either. Even inside a Macro

{%Documents.WithAllData[NodeAliasPath].GetValue("custom_field")|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 14, 2017 16:20 (last edited on December 10, 2019 02:30)

Since I'm not that familiar with custom queries (at all). I did some more research. I discover that using the web part "Universal Document viewer" is able to target the document without using Node Alias.

However it gives me all instances of the field I what to display.

Can I write something like this to only get the value of this field "postedbyPosition" if the Owner matches.

{% if (CurrentDocument.NodeOwner == 811) { return " + postedbyPosition +" } else return { "" } |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

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