How do I load a specific document that has been set using the form field "Page Selector"?

Simon Goldsmith asked on June 13, 2017 14:10

I have a custom Page Type which has 3 fields (RelatedPage1, RelatedPage2, RelatedPage3) where the user can use the "Page Selector" form field type to select a page from the site.

I am using a webpart and a query like below, but I don't know what the correct syntax is to pull back the 3 documents?

var RelatedPages = DocumentHelper.GetDocuments("csm.casestudy").Path("/our-work/%")...

How do I use the values stored in RelatedPage1, RelatedPage2, RelatedPage3 fields in a query to pull back those documents so I can render their information to the page in a .net repeater?

Many thanks, Simon

Correct Answer

Anton Grekhovodov answered on June 13, 2017 14:33

Hi Simon,
Page Selector saves NodeGuid value in database table. So your query will be like:

var RelatedPage1 = ValidationHelper.GetGuid(CurrentDocument.GetValue("RelatedPage1"), Guid.Empty);
...

var RelatedPages = DocumentHelper.GetDocuments("csm.casestudy")
            .Path("/our-work/%")
            .WhereEquals("NodeGuid", RelatedPage1)
            .Or().WhereEquals("NodeGuid", RelatedPage2)
            .Or().WhereEquals("NodeGuid", RelatedPage3)
            .ToList();

Or another variant:

var query = DocumentHelper.GetDocuments("csm.casestudy").Path("/our-work/%");

    for (var i = 1; i <= 3; i++)
    {
        var relatedPage = ValidationHelper.GetGuid(CurrentDocument.GetValue("RelatedPage" + i), Guid.Empty);
        if (relatedPage == Guid.Empty) continue;

        if (i > 1) query = query.Or();

        query = query.WhereEquals("NodeGuid", relatedPage);
    }

    var relatedPages = query.ToList();
1 votesVote for this answer Unmark Correct answer

Recent Answers


Simon Goldsmith answered on June 13, 2017 14:52

Absolutely awesome!!!! Thank you. I will make a note of this for the future!

0 votesVote for this answer Mark as a Correct answer

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