document function is working to get size and extenstion

HI team,

i want to find the type of extension and Size of list of documents and i have used document function and build an expression rule it is working fine in expression rule as expected when i call that expression in an interfcae  it is shoowing error as document function is deleted. 

a!localVariables(
  local!size: a!forEach(ri!documents, document(fv!item, "size")),
  local!extension: a!forEach(
    ri!documents,
    document(fv!item, "extension")
  ),
  toboolean(
    and(and(reject(
      fn!isnull,
      {
        a!forEach(
          local!extension,
          if(fv!item <> "pdf", false, null)
        )
      }
    )),
    and(reject(
      fn!isnull,
      {
        a!forEach(
          local!size,
          if(fv!item > 5000000, false, null)
        )
      }
    )
    )))
  
)

when i use in interface getting error as shown below

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Lead Developer
    in reply to NewBegineer

    Hi ,

    a!localVariables(
      local!document,
      local!documentContent,
      local!documentSize,
      local!documentExtension,
      {
        a!fileUploadField(
          label: "Documents",
          target: cons!APP_TEMPORARY_FOLDER,
          maxSelections: 1,
          value: local!document,
          saveInto: {
            local!document,
            a!save(
              local!documentContent,
              property(
                property(
                  a!fileUploadField(value: local!document),
                  "contents",
                  null
                ),
                "value",
                null
              )
            ),
            a!save(
              local!documentSize,
              property(
                local!documentContent,
                "fileSizeDisplay",
                null
              )
            ),
            a!save(
              local!documentExtension,
              property(local!documentContent, "extension", null)
            )
          }
        )
      }
    )

    You can use this code to get the metadata of uploaded document at runtime.

Children
  • Please note that this method is very unsupported and potentially buggy (and could stop working after any arbitrary update to the behind-the-scenes component code).

    Prior to the implementation of the file upload field "validations" parameters that enabled validating on these, I considered it (personally) acceptable to use this work-around if only for the sake of validating.  However now that we *can* validate on these aspects of uploaded files, directly using supported OOB functionality, I consider it too risky to use in any production sense (and won't personally recommend it or even directly hint at the capability anymore unless it's in a context where i know it'll be used only for testing or experimentation).  So I advise extreme caution / reservation, both for anyone considering adopting this approach, as well as for those providing it in threads here.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Totally agree with Mike's answer. I was in a assumption this is a legitimate approach.

     , I would also recommended to not use this method keeping all the risks highlighted by Mike.