Is there a plugin or a way to create a word document with information from the database?

Certified Associate Developer

Hi! I am currently using the smart service "MS Word 2007 Doc from Template" to generate a word with a default template and to be able to retrieve the data of a record within a label that can be printed as a sticker. My question is, is there a way that I can generate a word document with N records and when I retrieve that data each record is stored in a separate tag. It would be something like this:

Thanks for your help.

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    AFAIk there is no direct way of doing this. You could create that template to include all stickers and include a number in the placeholders to inject data at runtime.

  • 0
    Certified Lead Developer

    I'll preface to say that one of the more advanced Word Doc generation smart services may work more smoothely for this.  But my experience is mainly with the Word 2007 from Template smart service. 

    For this scenario, you would create a template with a single replacement key.  Then you're free to insert as much data as you want from Appian - for formatting, you'd need to make use of injecting WordML tags along with your (sanitized) text.  It would be hard to get a grid like in your example, but if you'd settle for a list of entries with nice linebreaks, it would be fairly simple to accomplish, because you'd just need to replace all text linebreaks with the WordML linebreak sequence.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Thanks for your answer. Could you give me an example of how to retrieve a series of records with the line break you mention? Currently I am only able to get the data from a single record.

  • 0
    Certified Lead Developer
    in reply to José Manuel Ojeda

    I'm unclear what you're asking here - are you saying you don't know how to query a list of data, as opposed to a single entry?  Are you using Data Store + a!queryEntity()?  Or are you using Synced Records?

    Edit: to clarify a bit, what we're talking about here in general is setting up a process model wherein some data is queried into local PV variables, for instance, and after that, the "Word from template..." smart service is called in such a way as to generate a document reflecting that queried data.  There isn't some magical one-stop tool to do everything all in one package, though some of the steps can be condensed slightly after you're confident in your methodology.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    I currently have these fields in my smart service:

    And I have this rule to retrieve the data from my table by a series of filters:

    a!localVariables(
      a!queryEntity(
        entity: cons!DEP_PsicologoDT_POINTER,
        query: {a!query(
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {      
              a!queryFilter(
                field: "idEmpleo.idEmpleo",
                operator: "=",
                value:ri!empleo.idEmpleo,
                applyWhen: not(isnull(ri!empleo.idEmpleo))
              ),            
              a!queryFilter(
                field: "coNombre",
                operator: "includes",
                value:ri!nombre,
                applyWhen: not(isnull(ri!nombre))
              ),
              a!queryFilter(
                field: "coDestino",
                operator: "includes",
                value:ri!destino,
                applyWhen: not(isnull(ri!destino))
              ),
              a!queryFilter(
                field: "idEjercito.idEjercito",
                operator: "=",
                value:ri!ejercito.idEjercito,
                applyWhen: not(isnull(ri!ejercito.idEjercito))
              ),
              a!queryFilter(
                field: "idEscala.idEscala",
                operator: "=",
                value:ri!escala.idEscala,
                applyWhen: not(isnull(ri!escala.idEscala))
              ),
              a!queryFilter(
                field: "idLocalidad",
                operator: "=",
                value:ri!localidad.idLocalidad,
                applyWhen: not(isnull(ri!localidad.idLocalidad))
              ),
              a!queryFilter(
                field: "idPuesto.idPuesto",
                operator: "=",
                value:ri!puesto.idPuesto,
                applyWhen: not(isnull(ri!puesto.idPuesto))
              ),
              a!queryFilter(
                field: "idLocalidad.idProvincia.idProvincia",
                operator: "=",
                value:ri!provincia.idProvincia,
                applyWhen: not(isnull(ri!provincia.idProvincia))
              ),
              a!queryFilter(
                field: "idLocalidad.idProvincia.idComunidadAutonoma.idComunidadAutonoma",
                operator: "=",
                value:ri!comunidad.idComunidadAutonoma,
                applyWhen: not(isnull(ri!comunidad.idComunidadAutonoma))
              ),
            }
          ),
          pagingInfo: if(isnull(ri!pagingInfo),a!pagingInfo(1,-1),ri!pagingInfo)
        )},
        fetchTotalCount: true
      ))

    But I don't know how to filter those records within my process model and how to put the line break between records

  • 0
    Certified Lead Developer
    in reply to José Manuel Ojeda
    I currently have these fields in my smart service:

    That means you currently have a template with all of the pictured replacement keys manually defined.  If you're trying to create a Word Document that would handle an arbitrary number (one or many) such entries, however, this won't work.  That's why I mentioned creating a template with a single replacement key, where you insert a block of text with injected XML for linebreaks.  To help you out, the XML code for a single linebreak would be the string: "</w:t><w:br/><w:t>"  (the "</w:t>" tag breaks out of regular text and allows you to insert code, which is the "<w:br/>" tag, then the following "<w:t>" tag begins regular text again)

    I don't know how to filter those records within my process

    Can you clarify what you mean by "filter within my process"?  Your query code attached filters on several fields already.  What are you unable to do "in the process model"?  What are you already trying?