Document viewer Field Help

How can we add something like an "Upload" or "Preview Document" button on the form that submits (typically without validation), and simply chains back to itself - this will give the user the impression they have not left the form, but turns the document into an official object that can then be previewed.

  Discussion posts and replies are publicly visible

Parents
  • This is pretty much as straightforward as adding a!buttonArrayLayout() on the interface that submits the form, then the form will chain back to itself - typically with a decision node to determine if they are asking for a preview, or submitting/canceling the form to move the process:

    A quick and dirty sample interface would be something like below with 2 inputs for document (document), and navigation (text):

    a!localVariables(
      local!document,
      /* there are more graceful ways to check for doc existance */
      local!documentExists: not(tostring(ri!document)="[Document:]"),
      a!formLayout(
        label: "Document Upload / Preview",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!fileUploadField(
                              value: local!document,
                              saveInto: local!document,
                              maxSelections: 1
                            )
                          ),
                          a!sideBySideItem(
                            item: a!buttonArrayLayout(
                              buttons: {
                                a!buttonWidget(
                                  label: "Preview Document",
                                  value: "PREVIEW",
                                  saveInto: {
                                    ri!navigation,
                                    a!save(ri!document,local!document)
                                  }
                                )
                              }
                            )
                          )
                        }
                      )
                    }
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!documentViewerField(
                        showWhen: local!documentExists,
                        document: ri!document
                      ),
                      a!richTextDisplayField(
                        showWhen: not(local!documentExists),
                        value: {
                          a!richTextItem(
                            text: "You must click Preview on the left for the document to be viewed",
                            style: "EMPHASIS"
                          )
                        }
                      )
                    }
                  )
                }
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              validate: true,
              submit: true,
              value: "SUBMIT",
              saveInto: {
                ri!navigation,
                a!save(ri!document,local!document)
              }
            )
          },
          secondaryButtons:  {
            a!buttonWidget(
              label: "Cancel",
              validate: false,
              submit: true,
              value: "CANCEL",
              saveInto: ri!navigation
            )
          }
        )
      )
    )

    Just to note, this is a continuation of the other thread on the topic.

  • 0
    Certified Senior Developer
    in reply to Chris

    I'm getting the error "Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!documentViewerField [line 51]: Document Does Not Exist or has been Deleted"

    Can someone please tell me what I'm doing wrong please.

    a!localVariables(
      local!document,
      /* there are more graceful ways to check for doc existance */
      local!documentExists: not(tostring(ri!document)= false()
      ),
      a!formLayout(
        label: "Document Upload / Preview",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!fileUploadField(
                              value: local!document,
                              saveInto: local!document,
                              maxSelections: 1
                            )
                          ),
                          a!sideBySideItem(
                            item: a!buttonArrayLayout(
                              buttons: {
                                a!buttonWidget(
                                  label: "Preview Document",
                                  value: "PREVIEW",
                                  saveInto: {
                                    ri!navigation,
                                    a!save(ri!document,local!document)
                                  }
                                )
                              }
                            )
                          )
                        }
                      )
                    }
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!documentViewerField(
                        showWhen: local!documentExists,
                        document: ri!document
                      ),
                      a!richTextDisplayField(
                        showWhen: not(local!documentExists),
                        value: {
                          a!richTextItem(
                            text: "You must click Preview on the left for the document to be viewed",
                            style: "EMPHASIS"
                          )
                        }
                      )
                    }
                  )
                }
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              validate: true,
              submit: true,
              value: "SUBMIT",
              saveInto: {
                ri!navigation,
                a!save(ri!document,local!document)
              }
            )
          },
          secondaryButtons:  {
            a!buttonWidget(
              label: "Cancel",
              validate: false,
              submit: true,
              value: "CANCEL",
              saveInto: ri!navigation
            )
          }
        )
      )
    )
    

  • 0
    Certified Lead Developer
    in reply to FrankT

    Why did you change the example code Chris gave you for local!documentExists?  The code you have in your expression here wouldn't do anything.  His original one would check whether the ri!document is empty, successfully (though honestly i'd just use a null checker on the rule input).

    Correct:

    Your version:

    The problem here is if your "local!documentExists" evaluates to TRUE when ri!document is actually empty, the preview field will attempt to show anyway, but with an invalid document, causing the error you posted.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    I replaced back as the original, but I still get the same error.

    a!localVariables(
      local!document,
      /* there are more graceful ways to check for doc existance */
      local!documentExists: not(tostring(ri!document)= "[Document:]"
      ),
      a!formLayout(
        label: "Document Upload / Preview",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!fileUploadField(
                              value: local!document,
                              saveInto: local!document,
                              maxSelections: 1
                            )
                          ),
                          a!sideBySideItem(
                            item: a!buttonArrayLayout(
                              buttons: {
                                a!buttonWidget(
                                  label: "Preview Document",
                                  value: "PREVIEW",
                                  saveInto: {
                                    ri!navigation,
                                    a!save(ri!document,local!document)
                                  }
                                )
                              }
                            )
                          )
                        }
                      )
                    }
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!documentViewerField(
                        showWhen: local!documentExists,
                        document: ri!document
                      ),
                      a!richTextDisplayField(
                        showWhen: not(local!documentExists),
                        value: {
                          a!richTextItem(
                            text: "You must click Preview on the left for the document to be viewed",
                            style: "EMPHASIS"
                          )
                        }
                      )
                    }
                  )
                }
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              validate: true,
              submit: true,
              value: "SUBMIT",
              saveInto: {
                ri!navigation,
                a!save(ri!document,local!document)
              }
            )
          },
          secondaryButtons:  {
            a!buttonWidget(
              label: "Cancel",
              validate: false,
              submit: true,
              value: "CANCEL",
              saveInto: ri!navigation
            )
          }
        )
      )
    )
    

  • 0
    Certified Lead Developer
    in reply to FrankT

    What sequence of events is bringing you to that error?  Are you using the form (and getting the error) in a process model setup?  Or are you trying to do it in the interface editor?

  • 0
    Certified Senior Developer
    in reply to FrankT

    Hi Frank I have made some changes in your code please check I have mentioned the comments.

    a!localVariables(
      local!document,
      /* there are more graceful ways to check for doc existance */
      local!documentExists: not(tostring(ri!document) = "[Document:]"),
      a!formLayout(
        label: "Document Upload / Preview",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!fileUploadField(
                              value: local!document,
                              saveInto: local!document,
                              maxSelections: 1,
                              target: cons!AA_DOCUMENTS_FOLDER_POINTER/*set the target for the documents*/
                            )
                          ),
                          a!sideBySideItem(
                            item: a!buttonArrayLayout(
                              buttons: {
                                a!buttonWidget(
                                  label: "Preview Document",
                                  value: "PREVIEW",
                                  submit: true(),/*mark submit as true*/
                                  saveInto: {
                                    ri!navigation,
                                    a!save(ri!document, local!document)
                                  }
                                )
                              }
                            )
                          )
                        }
                      )
                    }
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "Select Document",
                    style: "ACCENT",
                    contents: {
                      a!documentViewerField(
                        showWhen: local!documentExists,
                        document: ri!document
                      ),
                      a!richTextDisplayField(
                        showWhen: not(local!documentExists),
                        value: {
                          a!richTextItem(
                            text: "You must click Preview on the left for the document to be viewed",
                            style: "EMPHASIS"
                          )
                        }
                      )
                    }
                  )
                }
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              validate: true,
              submit: true,
              value: "SUBMIT",
              saveInto: {
                ri!navigation,
                a!save(ri!document, local!document)
              }
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              validate: false,
              submit: true,
              value: "CANCEL",
              saveInto: ri!navigation
            )
          }
        )
      )
    )

  • 0
    Certified Lead Developer
    in reply to ujjwalrathore

    That looks pretty similar - mind sharing exactly what the important change was?

    Never mind, I did a np++ diff, i see it now.  Good catch, I didn't notice originally that the 'Preview' button was not set for 'Submit'.

Reply Children