Skip to main content
September 16, 2022
Solved

How to get the No. of documents created last day

  • September 16, 2022
  • 3 replies
  • 0 views

I have requirement to get the no of documents created last day/yesterday in KC.

We have a function to get the number of documents present in KC :  knowledgecenter(ri!folderId,"numberOfDocuments")

Can anyone please how to approach. Thanks in advance

    Best answer by prafuls972

    a!localVariables(
    local!document: folder(
    cons!LSME_DOCUMENT_FOLDER,
    "documentChildren"
    ),
    local!dateCreated: a!forEach(
    items: local!document,
    expression: if(
    todate(document(fv!item, "dateCreated")) > today()-1,
    true(),
    false()
    )
    ),
    length(
    remove(
    local!dateCreated,
    wherecontains(false(), local!dateCreated)
    )
    )
    )

    3 replies

    prafuls972
    September 16, 2022

    a!localVariables(
    local!document: folder(
    cons!LSME_DOCUMENT_FOLDER,
    "documentChildren"
    ),
    local!dateCreated: a!forEach(
    items: local!document,
    expression: if(
    todate(document(fv!item, "dateCreated")) > today()-1,
    true(),
    false()
    )
    ),
    length(
    remove(
    local!dateCreated,
    wherecontains(false(), local!dateCreated)
    )
    )
    )

    September 19, 2022

    Thank you Prafuls0004. This solves my query

    stefanhelzle0001
    Brainy
    September 19, 2022

    An alternative approach

    a!localVariables(
      local!document: folder(
        cons!LSME_DOCUMENT_FOLDER,
        "documentChildren"
      ),
      sum(
        a!forEach(
          items: local!document,
          expression: todate(document(fv!item, "dateCreated")) > today()-1,
        )
      )
    )

    When converting a boolean value into an integer, it becomes 0 for false and 1 for true. We can use that to calculate the sum of true values in a boolean list.

    BTW, a comparison always evaluates to a boolean. Putting it into an if() will not make this a more elegant implementation.