documents Chat Field

Hi Team,

I am working with the documentsChatField in Appian. After uploading a document, I want to pass it to the chat field for verification. If the verification is successful, I need to save the document details in the database.

Could you please guide me on how to achieve this? Is it possible to trigger document verification immediately after upload and then conditionally persist the document metadata based on the verification result?

  Discussion posts and replies are publicly visible

Parents Reply Children
  • I have successfully implemented file upload using the fileUploadField component and obtained the document ID after upload. I would like to pass this document ID to the documentsChatField through a local variable in order to initiate a chat session with the uploaded document.

  • 0
    Certified Lead Developer
    in reply to rajeshp7374
    I would like to pass this document ID to the documentsChatField through a local variable in order to initiate a chat session with the uploaded document.

    Are you facing any issue with this?

  • The functionality stops working when I pass the new document ID. Please find the code below.

    a!localVariables(
    local!documentId,
    local!selectedValue,
    local!gridData: a!queryEntity(
    entity: cons!DS_SEARCH_DOCUMENT,
    query: a!query(
    logicalExpression: a!queryLogicalExpression(
    operator: "AND",
    filters: {
    a!queryFilter(
    field: "Id",
    operator: "in",
    value: tointeger(local!selectedValue),
    applyWhen: a!isNotNullOrEmpty(local!selectedValue)
    )
    },
    ignoreFiltersWithEmptyValues: true
    ),
    pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 50)
    ),
    fetchTotalCount: false
    ).data,
    local!docid: todocument(index(local!gridData, "documentId", {})),
    a!sectionLayout(
    label: "Section",
    contents: {
    a!fileUploadField(
    label: "File Upload",
    labelPosition: "COLLAPSED",
    fileNames:fv!file.name,
    value: local!documentId,
    saveInto: {
    local!documentId,
    a!save(
    ri!Document,
    'type!{urn:com:appian:types}Document_Upload_CDT'(
    documentId: local!documentId,
    documentName:local!documentId,
    /*attachmentType:fv!file.extension,*/
    description: "test",
    isActive: true(),
    CreatedBy: 12,
    CreatedOn: now()
    )
    )
    },
    maxSelections: 1,
    target: cons!DOCUMENT_SEARCH_UPLOAD
    ),
    a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Upload",
    submit: true,
    icon: "Upload",
    style: "SOLID"
    )
    }
    ),
    a!documentsChatField(
    label: "Documents Chat",
    documents:if(todocument(a!isNotNullOrEmpty(local!documentId)),local!docid,{}),
    height: "AUTO"
    ),
    a!gridField(
    label: "Read-only Grid",
    labelPosition: "ABOVE",
    data: a!queryEntity(
    entity: cons!DS_SEARCH_DOCUMENT,
    query: a!query(pagingInfo: fv!pagingInfo),
    fetchTotalCount: true
    ),
    columns: {
    a!gridColumn(
    label: "Id",
    value: a!defaultValue(fv!row.Id, "–"),
    sortField: "Id",
    align: "END"
    ),
    /*a!gridColumn(*/
    /*label: "Document Id",*/
    /*value: a!defaultValue(fv!row.documentId, "–"),*/
    /*sortField: "documentId",*/
    /*align: "END"*/
    /*),*/
    a!gridColumn(
    label: "Document Name",
    value:document(fv!row.documentId,"name"),
    sortField: "documentName"
    ),
    a!gridColumn(
    label: "Attachment Type",
    value: document(fv!row.documentId,"extension"),
    sortField: "attachmentType"
    ),
    a!gridColumn(
    label: "Description",
    value: a!defaultValue(fv!row.description, "–"),
    sortField: "description"
    ),
    a!gridColumn(
    label: "Is Active",
    value: if(
    isnull(fv!row.isActive),
    "–",
    a!richTextDisplayField(
    value: if(
    fv!row.isActive,
    a!richTextIcon(
    icon: "check",
    altText: "Yes",
    color: "#138901"
    ),
    a!richTextIcon(
    icon: "times",
    altText: "No",
    color: "SECONDARY"
    )
    )
    )
    ),
    sortField: "isActive",
    align: "CENTER"
    )
    },
    selectable: true,
    selectionValue: local!selectedValue,
    selectionSaveInto: local!selectedValue,
    height: "AUTO",
    shadeAlternateRows: true
    )
    }
    ),

    )

  • 0
    Certified Lead Developer
    in reply to rajeshp7374

    Replace local!docid with toDocument(local!documentId) directly in chat field.
    Fix the if() condition - remove todocument() wrapping the boolean
    Capture upload via index(fv!files, 1, null())

  • +1
    Certified Lead Developer
    in reply to rajeshp7374

    The AI components can not access 'un-submitted' files.  Files that are freshly uploaded live in a special hidden part of the Appian back-end filesystem and until recently even functions like "document()" would error when trying to use them before the document was "submitted" (though this has been updated in the past ~2 versions).

    To handle your use case though, you'll need to do one of these:

    • If this is in a User Input Task, you'll need to submit the task and (usually) loop back to the same task again, feeding in the ID of the now-submitted document. 
    • If it's in a Site page, you can call "a!submitUploadedFiles()" somewhere in a SaveInto which will promote the newly-uploaded file to the part of the Appian filesystem that the AI tools can access.