0

I am trying to retrieve all the documents within a specified folder (including subfolders) and order them Ascending. I am getting all the documents but they are not ordered.

This is what I have so far:

const libraryName = "Approved Policies and Procedures";
const groupFolderPath = `${this._pageContext.web.serverRelativeUrl}/Approved Policies and Procedures/1. Telkom Group`;
const corpFolderPath = `${this._pageContext.web.serverRelativeUrl}/Approved Policies and Procedures/4. Corp Centre`;

const groupQuery = `
    <View Scope="RecursiveAll">
      <Query>
        <OrderBy>
            <FieldRef Name="Title" Ascending='True'/>
        </OrderBy>
        <Where>
            <And>
              <Eq>
                <FieldRef Name="FSObjType" />
                <Value Type="Integer">0</Value>
              </Eq>
                <BeginsWith>
                  <FieldRef Name="FileRef" />
                  <Value Type="Text">${groupFolderPath}</Value>
                </BeginsWith>
            </And>
        </Where>
        </Query>
    </View>
  `;

I have tried adding the ORDERBY after the WHERE clause, but still not ordered!

Any help\guidance will be appreciated

1
  • Can you share the line where you use groupQuery?
    – jleture
    Oct 24, 2023 at 13:35

1 Answer 1

0

If you want to order files by name, you have to use FileLeafRefand not Title

const groupQuery = `
    <View Scope="RecursiveAll">
      <Query>
        <OrderBy>
            <FieldRef Name="FileLeafRef" Ascending='True'/>
        </OrderBy>
        <Where>
            <And>
              <Eq>
                <FieldRef Name="FSObjType" />
                <Value Type="Integer">0</Value>
              </Eq>
                <BeginsWith>
                  <FieldRef Name="FileRef" />
                  <Value Type="Text">${groupFolderPath}</Value>
                </BeginsWith>
            </And>
        </Where>
        </Query>
    </View>
  `;
1
  • This resolved my issue, many thanks
    – Johan v Dk
    Oct 25, 2023 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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