Export pivoted data in excel

Certified Lead Developer

Hi All,

I would need an help in understanding is there any way i can PIVOT the table data and export it to excel.

Currently my table has data

I would need the response in excel as 

Basically "Questions" column as row header in excel and Answers as row response.

Help is appreciated.

Thanks in advance

  Discussion posts and replies are publicly visible

Parents
  • /* Create a webapi object and place the below code */
    
    a!localVariables(
      /*call your table to fetch two columns and all the rows*/
      local!data,
      local!questionRow: concat(
        a!forEach(
          items: local!data,
          expression: { fv!item.questions, "," }
        )
      ),
      local!answerRow: concat(
        a!forEach(
          items: local!data,
          expression: { fv!item.answers, "," }
        )
      ),
      a!httpResponse(
        /*
        * Set an HTTP header that tells the client that the body of the response
        * will be a CSV attachment.
        */
        headers: {
          a!httpHeader(
            name: "Content-Disposition",
            value: "attachment; filename=" & char(34) & "Test.csv" & char(34)
          )
        },
        /*
        * Create a CSV value of 'local!questions', 'local!anwers'  and place it in the response body.
        */
        body: {
          local!questionRow & char(10) & local!answerRow
        }
      )
    )

Reply
  • /* Create a webapi object and place the below code */
    
    a!localVariables(
      /*call your table to fetch two columns and all the rows*/
      local!data,
      local!questionRow: concat(
        a!forEach(
          items: local!data,
          expression: { fv!item.questions, "," }
        )
      ),
      local!answerRow: concat(
        a!forEach(
          items: local!data,
          expression: { fv!item.answers, "," }
        )
      ),
      a!httpResponse(
        /*
        * Set an HTTP header that tells the client that the body of the response
        * will be a CSV attachment.
        */
        headers: {
          a!httpHeader(
            name: "Content-Disposition",
            value: "attachment; filename=" & char(34) & "Test.csv" & char(34)
          )
        },
        /*
        * Create a CSV value of 'local!questions', 'local!anwers'  and place it in the response body.
        */
        body: {
          local!questionRow & char(10) & local!answerRow
        }
      )
    )

Children