Skip to main content
Known Participant
Sep 7, 2022 4:13 AM UTC
Question

Error when use function document()

In my interface, I user function document.

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

    22 replies

    Inspiring
    Sep 7, 2022 4:37 AM UTC

    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
    Known Participant
    Sep 7, 2022 4:53 AM UTC

    I tried, but It also error like that

    Inspiring
    Sep 7, 2022 4:54 AM UTC

    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?

    Inspiring
    Sep 7, 2022 4:45 AM UTC

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

     

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

    khuud0002Author
    Known Participant
    Sep 7, 2022 4:59 AM UTC

    It also error.

    Inspiring
    Sep 7, 2022 5:00 AM UTC

    show me the error along with rule input.

    Participating Frequently
    Sep 7, 2022 5:59 AM UTC

    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
    Sep 7, 2022 12:39 PM UTC

    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
    Sep 7, 2022 1:21 PM UTC

    Yes I agree.

    mikes0011
    Brainy
    Sep 7, 2022 12:33 PM UTC

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

    The Expression Guru
    Known Participant
    Sep 7, 2022 1:45 PM UTC

    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), {}),
      ""
    )