Skip to main content
September 7, 2022
Question

Error when use function document()

  • September 7, 2022
  • 22 replies
  • 1 view

In my interface, I user function document.

if(
                            document(tofolder(local!documentId), "size") > 0,
                            true,
                            false
                          )

    22 replies

    Inspiring
    September 7, 2022

    Hi,

    Looks like the provided document id have null value (local!documentId). You can add null check condition to solve this issue. See below sample code

    if(
      and(
        a!isNotNullOrEmpty(local!documentId),
        document(tofolder(local!documentId), "size") > 0
      ),
      true,
      false
    )

    khuud0002Author
    September 7, 2022

    I tried, but It also error like that

    September 7, 2022

    show us the error. What input you are giving to the rule input. check whether the document is available for the id you entered or not?

    September 7, 2022

    In document function, you have to provide documentId not the folder id.

     

    if(
      document(todocument(ri!documentId), "size") > 0,
      true,
      false
    )

    khuud0002Author
    September 7, 2022

    It also error.

    September 7, 2022

    show me the error along with rule input.

    Participating Frequently
    September 7, 2022

    Create a rule with the below to check whether the document is valid or not.

    a!localVariables(
      local!document: 46,/*ID for any document */
      local!contentData: if(
        isnull(local!document),
        null,
        getcontentobjectdetailsbyid(local!document)
      ),
      if(
        isnull(local!document),
        false(),
        and(
          not(
            exact(
              local!contentData,
              "No object with this ID has been found"
            )
          ),
          find("Type: Document", local!contentData)
        )
      )
    )

    mikes0011
    Brainy
    September 7, 2022

    FYI, this rule won't work for just-uploaded documents, because it'll indicate that the document is "valid" even when newly uploaded on an unsubmitted form, but the document will still fail when using the "document()" function because the document isn't in an Active/Published status.

    The Expression Guru
    Participating Frequently
    September 7, 2022

    Yes I agree.

    mikes0011
    Brainy
    September 7, 2022

    Where / how is the value of "local!documentId" being set?

    The Expression Guru
    September 7, 2022

    try this for newly uploaded documents

    validations: if(
      or(fv!files.size < 0),
      "Attachments must be at least 1kn. Remove: " &
        index(fv!files, "name", where(fv!files.size < 0), {}),
      ""
    )