Any alternative for findfoldersbyname()

Hi Everyone,

Please suggest me alternative for findfoldersbyname() function.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    The functions findFoldersByName and findDocumentByName don't scale once you have hundreds of thousands of documents - I've seen returns from these functions of 7 or more seconds; pretty bad.

    The short answer is store the folder and/or document ID in the database. However, if you absolutely must retrieve, for example, the documents within a folder, it's possible to write an expression that does something similar - see below. Note that the same principle can be applied to finding a folder by name within a specific folder.

    load(
      local!allFolderDocuments: fn!getdocumentsfromfolder(
        ri!folder,
        false
      ),
      local!allFolderDocumentNames: a!forEach(
        items: local!allFolderDocuments,
        expression: document(
          fv!item,
          "name"
        )
      ),
      index(
        index(
          local!allFolderDocuments,
          wherecontains(
            ri!documentName,
            local!allFolderDocumentNames
          ),
          tointeger(
            {}
          )
        ),
        1,
        null
      )
    )

  • Thanks for responding, Actually contentfunctions plugin is deprecated hence I need any alternative for findfoldersbyname() function.

    To specify more about my requirement, end users of my application upload some documents while raising a request, during the flow we are creating a folder with name as ID of this request and we will be storing the documents in this folder and data is stored in DB but we are not capturing the folder ID in DB.

    Further more to this request we have a related action wherein user can upload more documents to this folder, so in this scenario the process model of the related action will be having only folder name taken from rf!requestID, so I need to identify the folder by its name so that the further uploaded documents to be stored in the correct folder.
  • I would recommend to store the folder id against unique id ( requestId in your case) in a separate table. We did the same in our implementation.

    Regards
    Bala K
  • Thanks everyone for your response.

    I have achieved the requirement with help of my colleague. Here the constant is holding the parent folder whit in which we are creating the new folders for every new request, and rule input is we are passing the folder name that we want to search.

    with(
    local!allFolderId:tointeger(
    folder(tointeger(cons!GOE_UPLOAD_DOCUMENT_FOLDER),"folderChildren")
    ),
    local!folderName:apply(
    folder(
    folderId :_,
    property :"name"
    ),
    local!allFolderId
    ),
    index(
    local!allFolderId,
    wherecontains(
    ri!folderName,
    local!folderName
    )

    )
    )