Show and Hide Fields in a Template

Certified Associate Developer

I've created an interface that shows and hides various fields based on the inputs in other fields. I'm now trying to make a document (preferably a PDF) that will display the data collected in the interface and ultimately be emailed to the customer. However it looks like the templates you have to make to use the "...Doc from Template" Smart Services are static and not capable of changing based on variables.

Does anyone have an idea on how to create a dynamic template that can change based on your data? I've thought about using PHP code inside of a HTML document but I'm not sure if/how that will work.

I've attached pictures of one of the dynamic aspects of my interface as well as the code associated with it.

a!multipleDropdownField(
                    label: if(
                      or(
                        ri!SealModel = "DRC",
                        ri!SealModel = "DTP",
                        ri!SealModel = "DRP",
                        ri!SealModel = "SMD",
                        ri!SealModel = "DGS",
                        ri!SealModel = "EDP",
                        ri!SealModel = "RBD",
                        ri!SealModel = "ESD",
                        ri!SealModel = "UMC",
                        ri!SealModel = "PRO",
                        ri!SealModel = "PDM",
                        ri!SealModel = "KMS"
                      ),
                      "Inboard Rotary Face:",
                      "Rotary Face:"
                    ),
                    labelPosition: "ABOVE",
                    placeholder: "Choose symptoms",
                    choiceLabels: {
                      "Missing",
                      "Carbon Dusting",
                      "Chipped",
                      "Cracked",
                      "Broken",
                      "Corroded",
                      "Pitted",
                      "Eroded",
                      "Leached",
                      "Blistered",
                      "Heat Checked",
                      "Thermal Markings",
                      "Product Residue",
                      "Rubbed",
                      "Worn",
                      "Grooved",
                      "Heavily Damaged",
                      "Plugged",
                      "Dented"
                    },
                    choiceValues: {
                      "Missing",
                      "Carbon Dusting",
                      "Chipped",
                      "Cracked",
                      "Broken",
                      "Corroded",
                      "Pitted",
                      "Eroded",
                      "Leached",
                      "Blistered",
                      "Heat Checked",
                      "Thermal Markings",
                      "Product Residue",
                      "Rubbed",
                      "Worn",
                      "Grooved",
                      "Heavily Damaged",
                      "Plugged",
                      "Dented"
                    },
                    value: ri!IBRotFaceSym,
                    saveInto: ri!IBRotFaceSym,
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                )
              },
              alignVertical: "MIDDLE"
            ),
            /* IB Rotary Face */
            a!forEach(
              ri!IBRotFaceSym,
              a!localVariables(
                local!numarray: { 1 },
                local!Label: fv!item,
                a!forEach(
                  local!numarray,
                  a!localVariables(
                    local!Sev,
                    local!Loc,
                    local!Pic,
                    local!num: index(local!numarray, length(local!numarray)),
                    a!columnsLayout(
                      columns: {
                        a!columnLayout(
                          contents: {
                            a!sideBySideLayout(
                              items: {
                                a!sideBySideItem(
                                  item: a!dropdownField(
                                    label: local!Label & " Severity",
                                    labelPosition: "ADJACENT",
                                    placeholder: "--- Select a Value ---",
                                    choiceLabels: {
                                      "N/A",
                                      "Light",
                                      "Moderate",
                                      "Heavy",
                                      "Extreme"
                                    },
                                    choiceValues: {
                                      "N/A",
                                      "Light",
                                      "Moderate",
                                      "Heavy",
                                      "Extreme"
                                    },
                                    value: local!Sev,
                                    saveInto: { local!Sev },
                                    validations: {}
                                  )
                                ),
                                a!sideBySideItem(
                                  item: a!dropdownField(
                                    label: local!Label & " Location",
                                    labelPosition: "ADJACENT",
                                    placeholder: "--- Select a Value ---",
                                    choiceLabels: {
                                      "N/A",
                                      "ID",
                                      "OD",
                                      "Face",
                                      "Face ID",
                                      "Face OD",
                                      "Pin Slot",
                                      "Multiple Locations"
                                    },
                                    choiceValues: {
                                      "N/A",
                                      "ID",
                                      "OD",
                                      "Face",
                                      "Face ID",
                                      "Face OD",
                                      "Pin Slot",
                                      "Multiple Locations"
                                    },
                                    value: local!Loc,
                                    saveInto: { local!Loc },
                                    searchDisplay: "AUTO",
                                    validations: {}
                                  )
                                ),
                                a!sideBySideItem(
                                  item: a!fileUploadField(
                                    label: "Upload Photos",
                                    labelPosition: "ADJACENT",
                                    target: cons!IBRotFacePics,
                                    fileNames: ri!ControlNumber & " IB Rotary Face " & local!Label & " " & fv!index,
                                    value: local!Pic,
                                    saveInto: local!Pic,
                                    validations: {},
                                    buttonStyle: "SECONDARY"
                                  ),
                                  width: "MINIMIZE"
                                )
                              }
                            ),
                            a!sideBySideLayout(
                              items: {
                                a!sideBySideItem(
                                  item: a!linkField(
                                    links: {
                                      a!dynamicLink(
                                        label: "Add Location",
                                        value: append(local!numarray, local!num + 1),
                                        saveInto: local!numarray,
                                        showWhen: if(
                                          local!numarray[length(local!numarray)] =< fv!item,
                                          true(),
                                          false()
                                        )
                                      )
                                    }
                                  ),
                                  width: "MINIMIZE"
                                ),
                                a!sideBySideItem(
                                  item: a!linkField(
                                    links: {
                                      a!dynamicLink(
                                        label: "Remove Location",
                                        value: remove(local!numarray, fv!index),
                                        saveInto: local!numarray
                                      )
                                    }
                                  ),
                                  width: "MINIMIZE"
                                )
                              }
                            )
                          }
                        )
                      }
                    )
                  )
                )
              )
            ),

  Discussion posts and replies are publicly visible

Parents
  • An approach I've gotten to work to some extent in the past is manually building an HTML file using in-Appian logic to parse your data and construct the necessary HTML code (which isn't all that hard depending on your complexity requirements), then passing the resulting HTML file through the PDF from HTML node, which generates a good (if rather plain) PDF.

    Secondarily - there's powerful functionality available within the OOB "Docx from Template" smart service because you can have a document with a single replacement field, and inject WordML code into it sufficient to construct any number of formatted paragraphs and even tables.  So it kinda depends on whether you're ultimately required to use PDF or not.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Thanks for your response! Would you mind explaining how to build an HTML file using in-Appian logic a little bit more? It sounds like it could be a good solution for me.

Reply Children