0

I have a list of documents who have a property (Related document ID) that I want to filter via query string

Example:

site.com/document?PolicyID=1

should view only documents who have the related ID = 1

I was thinking of using a Highlighted Content web part with a custom CAML query.

This is what I have so far:

<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Related_x0020_Document_x003a_ID'/>
<Value Type='Text'>{QueryString:PolicyID}</Value>
</Eq>
</Where>
</Query>
</View>

Can anyone with a basic understanding explain how it works?

I just want CAML to accept a query string on Sharepoint: https://i.imgur.com/077K0Mp.png

0

Not sure if this will help you, but you don't necessarily need to pass any values to a custom CAML query in order to use query params for filtering. SharePoint already has a built-in mechanism for doing this when looking at list views: FilterField and FilterValue.

So for instance, in your case you could apply the filtering you want by constructing a URL like:

https://your.sharepoint.site/lists/your-doc-library/AllItems.aspx?FilterField1=PolicyID&FilterValue1=1

Notice that there's a 1 tacked on the end of those params: FilterField1 and FilterValue1. So that also means you can apply multiple filters by using FilterField2/FilterValue2, etc.

There's another similar question and answer here.

  • Thank you Dylan. I can filter the original document library using this method but I want this to apply to a web part (I have tried 'Highlighted Content' and 'Document Library' web parts. I am doing site.com/Page.aspx?FilterField1=Related_x0020_Document_x003a_ID&FilterValue1=1&FilterType1=Lookup – trojanhorse Oct 24 '19 at 10:32
0

You could just concatenate it into the string. Hope it helps you:

Query.ViewXml ="<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Related_x0020_Document_x003a_ID'/>
<Value Type='Text'>" + yourParameter + " </Value>
</Eq>
</Where>
</Query>
</View>"
  • Thanks Michael, not sure how I can concatenate my paramter through Sharepoint though, take a look at this image: i.imgur.com/077K0Mp.png – trojanhorse Oct 24 '19 at 10:23
  • What's the policy ID? Where you define it? In the url? – Michael Han_MSFT Oct 31 '19 at 9:48
  • Policy ID is a property on the column I created, which is a look up to the document in another collection that it links to e.g. 'Finance Document' will have a linked 'Expenses Document' whose PolicyID is the same ID as Finance document – trojanhorse Nov 1 '19 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.