cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting as csv

johan1974
Champ in-the-making
Champ in-the-making
Hello,

I like to export some data with a webscript in a csv format. Where can i find a good explanation how to do this?

Thnx!
15 REPLIES 15

zaizi
Champ in-the-making
Champ in-the-making
Hi,

Read through the webscript wiki page at http://wiki.alfresco.com/wiki/Web_Scripts.

Set the response format to text. This is the format of the response data when the web script is called.

In your freemarker template just loop through and output the required fields separated by commas. You can also try using a macro to enclose fields in quotes or escape any commas in the field.

Ainga

johan1974
Champ in-the-making
Champ in-the-making
I did read this article but it gives me little info on how to build such csv file. I found an example called "docaudit" at the content community "My Alfresco > Webinar Slides > Alfresco Webscripts Webinar" but when i execute this example i get the same error i got with my own script.

Alfresco     Web Script Status 500 - Internal Error

The Web Script /alfresco/service/docaudit/User Homes/Administrator/setuplog.txt.csv has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Web Script format 'csv' is not registered

Exception:   org.alfresco.web.scripts.WebScriptException - Web Script format 'csv' is not registered
   
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:93)
   org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:364)
   org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:330)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:241)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:171)
   org.alfresco.web.scripts.WebScriptRuntime.transactionedExecute(WebScriptRuntime.java:341)
   org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:284)
   org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:150)
   org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   java.lang.Thread.run(Thread.java:619)
   
Server:   Alfresco Enterprise Network v2.2.0 (159) schema 89
Time:   29-apr-2008 9:53:27

Diagnostics:   Inspect Web Script (docaudit.get)

I did refresh at the service/index page. Do i need to do more registration for an csv file to create?

I would like a simple small  working example that i can use to expand and learn from.

Thnx!

dinger
Champ in-the-making
Champ in-the-making
You'll need to create your own web script that converts the output into csv.

See the webscripts examples in the wiki!

Rob

johan1974
Champ in-the-making
Champ in-the-making
I tried this and i can get some html and xml output. But i can not get a good working csv output. In the examples you mention are no csv examples.

zaizi
Champ in-the-making
Champ in-the-making
Hi,

CSV is just file formatting for what is essentially a text file with mime type 'text/plain'. Quick solution is to thus use .txt format on the webscript to respond with a text file and use freemarker to render the contents comma separated.

If you want the response to have a different mime type such as 'text/csv' or 'application/excel' then you will need to write your own custom java backed web script.

Which one did you have in mind?

Ainga

johan1974
Champ in-the-making
Champ in-the-making
At the moment i am interested in a csv response. Is it possible to see a small example where i can work with ?

mikeh
Star Contributor
Star Contributor
Rename setuplog.txt.csv to setuplog.csv.ftl

Thanks,
Mike

johan1974
Champ in-the-making
Champ in-the-making
Setuplog.txt.csv is not the actual ftl file. It happens to be in the folder i am looking.

For example when i look in the data Dictionary i get the same error but with the name of the data dictionary.

Alfresco     Web Script Status 500 - Internal Error

The Web Script /alfresco/service/docaudit/Data Dictionary.csv has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Web Script format 'csv' is not registered

Exception:   org.alfresco.web.scripts.WebScriptException - Web Script format 'csv' is not registered
   
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:93)
   org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:364)
   org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:330)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:241)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:171)
   org.alfresco.web.scripts.WebScriptRuntime.transactionedExecute(WebScriptRuntime.java:341)
   org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:284)
   org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:150)
   org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   java.lang.Thread.run(Thread.java:619)
   
Server:   Alfresco Enterprise Network v2.2.0 (159) schema 89
Time:   30-apr-2008 15:06:19

Diagnostics:   Inspect Web Script (docaudit.get)

mikeh
Star Contributor
Star Contributor
Ok, then the question should be: why are you trying to execute the .csv file as a webscript? That is why you're getting the exception - do you mean to pass-in the path to the .csv to the webscript?

Mike