Exporting the data into excel with a date range.

Hi,

I have a data in an an entity. I would like to pass two different dates and fetch the data between those dates and at the same time I would like to export to excel.

Can someone advise how can I can achieve this.

I found "Export Data Store Entity to Excel", but not sure whether this service will support date ranges to get the data from Data Store Entity.

Thanks.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    You can go with the Export DSE to Excel smart service, it works perfectly fine with your use case I have tried it personally, you just need to add between date range a!queryFilter just as you do in any a!queryentity().

    Below is the sample code for it


    a!localVariables(
      local!exportDocId,
      local!errorMessage,
      {
        if(
          isnull(local!exportDocId),
          /*This link field contains the link that starts the export*/
          a!linkField(
            labelPosition: "COLLAPSED",
            links: a!dynamicLink(
              label: "Export to Excel File",
              saveInto: {
                a!exportDataStoreEntityToExcel(
                  entity: cons!AA_VEHICLES_DSE_POINTER,
                  documentName: "Excel Export " & now(),
                  saveInFolder: cons!PA_FOLDER_ARTIFACTS,
                  filters: a!queryFilter(
                    field: "vehicleLastModifiedDate",
                    operator: "between",
                    value: { todate("10/06/2021"), today() }
                  ),
                  onSuccess: a!save(local!exportDocId, fv!newDocument),
                  /*This displays an error if there is an issue executing the save*/
                  onError: a!save(
                    local!errorMessage,
                    "Error Exporting File to Excel"
                  )
                )
              }
            )
          ),
          {}
        ),
        if(
          /*This only displays the download link if a valid document was created*/
          not(isnull(local!exportDocId)),
          /*This changes the link to a download link for the newly created document */
          a!linkField(
            links: a!documentDownloadLink(
              label: "Download Excel File",
              document: local!exportDocId
            )
          ),
          a!textField(value: local!errorMessage, readOnly: true)
        )
      }
    )

Reply
  • 0
    Certified Associate Developer

    You can go with the Export DSE to Excel smart service, it works perfectly fine with your use case I have tried it personally, you just need to add between date range a!queryFilter just as you do in any a!queryentity().

    Below is the sample code for it


    a!localVariables(
      local!exportDocId,
      local!errorMessage,
      {
        if(
          isnull(local!exportDocId),
          /*This link field contains the link that starts the export*/
          a!linkField(
            labelPosition: "COLLAPSED",
            links: a!dynamicLink(
              label: "Export to Excel File",
              saveInto: {
                a!exportDataStoreEntityToExcel(
                  entity: cons!AA_VEHICLES_DSE_POINTER,
                  documentName: "Excel Export " & now(),
                  saveInFolder: cons!PA_FOLDER_ARTIFACTS,
                  filters: a!queryFilter(
                    field: "vehicleLastModifiedDate",
                    operator: "between",
                    value: { todate("10/06/2021"), today() }
                  ),
                  onSuccess: a!save(local!exportDocId, fv!newDocument),
                  /*This displays an error if there is an issue executing the save*/
                  onError: a!save(
                    local!errorMessage,
                    "Error Exporting File to Excel"
                  )
                )
              }
            )
          ),
          {}
        ),
        if(
          /*This only displays the download link if a valid document was created*/
          not(isnull(local!exportDocId)),
          /*This changes the link to a download link for the newly created document */
          a!linkField(
            links: a!documentDownloadLink(
              label: "Download Excel File",
              document: local!exportDocId
            )
          ),
          a!textField(value: local!errorMessage, readOnly: true)
        )
      }
    )

Children