Retrieve Fields via Document Selector and Repeater

Frederik Kohleick asked on August 25, 2014 11:58

Hello dear friends. Hope you may help me.

I have a document type with a field of the type DocumentSelector.

When I create a document by this type I want to select another document type and retrieve the values of this documents fields.

I get the guid of the document but how do I get a field value by this guid? Tried various K# commands - all without success.

In earlier versions of Kentico this was possible by creating a custom Macro but this doesn't work anymore. Could you please give me a code example how to achieve this?

Thanks in advance!

Correct Answer

Jan Hermann answered on September 24, 2014 09:53

I don't know why it trimmed apostrophes around the GUID, but please try this:

{%Documents.ClassNames("custom.mydoctype").WithAllData.Where("NodeGUID='"+YourDocSelectorField+"'").FirstItem.DocumentName|(identity)GlobalAdministrator%}

Best regards,
Jan Hermann

1 votesVote for this answer Unmark Correct answer

Recent Answers


Frederik Kohleick answered on August 27, 2014 12:53

Can no one help me here? Come on guys.... please.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on September 15, 2014 10:08 (last edited on December 10, 2019 02:30)

Hello,

could you please try this:

{%Documents.ClassNames("custom.mydoctype").WithAllData.Where("NodeGUID="+YourDocSelectorField).FirstItem.DocumentName|(identity)GlobalAdministrator%}

Best regards,
Jan Hermann

0 votesVote for this answer Mark as a Correct answer

Markus Gruen answered on September 23, 2014 16:34

Hello Jan, thank you. But this results into this particular error and query:

SELECT * FROM View_CMS_Tree_Joined_Versions INNER JOIN skf_person ON View_CMS_Tree_Joined_Versions.DocumentForeignKeyValue = skf_person.PersonID WHERE (ClassName = N'skf.person') AND (((NodeSiteID = 2) AND (Published = 1)) AND (NodeGUID=89b0ba77-4005-4a5b-a2b0-ecc7dcf4162b)) ORDER BY NodeLevel, NodeAlias

0 votesVote for this answer Mark as a Correct answer

Markus Gruen answered on September 25, 2014 09:20

Dear Jan. Thank you for your kind and swift reply. Now I can see the output of the specified fields - but ONLY IF LOGGED IN in Kentico.

My goal is that the visitors may see this, too. Why isn't the output displayed to unauthenticated users. I checked if "display to roles" settings of the static text webpart were set to a certain value - but no.

This is what I see when logged in: Image Text

This is visible for unauthenticated users

Image Text

Any ideas on this?

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on September 25, 2014 09:36

Due to security reasons we added a permissions check, so the CMSContext takes data according to permissions of current user (public user when you are not signed in). There are many options you can follow now, however the simplest solution is to add the key below to your web.config file:

<add key="CMSCheckPermissionsForDocumentCollection" value="False"/>

Best regards,
Jan Hermann

1 votesVote for this answer Mark as a Correct answer

Markus Gruen answered on September 25, 2014 09:56

THANKS! This was the solution! Greatly appreciated.

0 votesVote for this answer Mark as a Correct answer

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