Document Does Not Exist or has been Deleted

I created an interface to upload a document and i am trying to capture the document name during the upload process. Following is the piece of code for the expression rule that i have been calling in a Script task.

a!flatten(
  a!forEach(
    items: ri!attachments,
    expression: if(
      rule!app_isBlank(fv!item.attachmentType),
      {},
      updatedictionary(
        dictionary: fv!item,
        fieldsAndValues: {
          recordId: ri!actionid,
          documentName: if(
            rule!app_isBlank(fv!item.documentId),
            null(),
            document(fv!item.documentId, "name")
          ),
          documentType: "",
          modifiedBy: "user@gmail.com",
          modifiedDt: now()
        }
      )
    )
  )
)

However, i keep getting the following error:

Expression evaluation error in rule at function a!forEach [line 2]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function 'document' [line 14]: Document Does Not Exist or has been Deleted) (Data Outputs)

I looked at some of the explanations on this issue but i am not able to figure it out. Thank you for the help.

  Discussion posts and replies are publicly visible