Dynamically look up a list item based on a variable using only CAML query

Phillips, Keith 601 Reputation points
2023-05-15T16:46:40.8466667+00:00

Using only CAML, is it possible to query the values of a field in a list based on the values of a field in a different list? I know it can be done using methods to build the query in other languages, i.e., Powershell, C#, etc., but I've got a SCORCH admin who's trying to use CAML without asking for a custom script/program.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
7,070 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
1,975 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 19,966 Reputation points Microsoft Vendor
    2023-05-16T07:17:15.7366667+00:00

    Hi @Phillips, Keith

    Lookup fields in SharePoint allow users to select a value from another list, which is then linked to the current list item. Lookup fields are used to create a relationship between two lists. CAML (Collaborative Application Markup Language) is an XML-based query language used in SharePoint to query data from lists and libraries.

    Let’s filter projects by parent project lookup field value “Address Book”. Here is the SharePoint CAML for a lookup field.

    <View Scope='RecursiveAll'>
        <Query>
            <Where>
                <Eq>
                    <FieldRef Name='ParentProject'/><Value Type='Lookup'>Address Book</Value>
                </Eq>
            </Where>
        </Query>
    </View>
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Phillips, Keith 601 Reputation points
    2023-05-26T10:51:12.9366667+00:00

    The person I'm helping with this has decided to use a PowerShell script to get what he needs done, as it's not possible for him to use a dynamically-created CAML query in Scorch.

    0 comments No comments