RE: How to retrieve data from DB inside JS File?

thumbnail
Mahammad Ashik A, modified 6 Years ago. Junior Member Posts: 81 Join Date: 7/17/17 Recent Posts
Hi,

How to retrieve data from DB inside JS File and how i can implement this?

Thanks in Advance
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
You are a bit ambiguous here.

1) Do you want to fetch data using javascript in the browser and display it there? In that case, you probably need to use ajax and create a backend rest service (or maybe a portlet with serveResource) that sends you the data.

2) Or do you want to fetch the data in the backend, write it in a page and use it there in javascript?

3) Or do you actually want to write the data in a javascript file? I would advise against that idea, but it is basically the same as option 2.
thumbnail
Mahammad Ashik A, modified 6 Years ago. Junior Member Posts: 81 Join Date: 7/17/17 Recent Posts
Thanks for your reply.


I created DDL form and storing data in DB. Now i need to generate report using D3.js based on data.


How i can implement this?
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
I am not sure here, but I believe you have to read the data using DDLRecordLocalService (or maybe DDLRecordService, in case you need to check permissions)
https://docs.liferay.com/dxp/apps/forms-and-workflow/7.0.6/javadocs/com/liferay/dynamic/data/lists/service/DDLRecordLocalService.html
thumbnail
Mahammad Ashik A, modified 6 Years ago. Junior Member Posts: 81 Join Date: 7/17/17 Recent Posts
Yes . I have to call Ddlrecord service but i am not sure how to call that service inside js file?

Any Idea?
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
You can't call that service directly from Javascript. Well, that's not exactly true. You can call the DDLRecordService through ajax. You can find the rest service under the path /api/jsonws when you select "ddl" in the dropdown.

I usually found these services rather inconvenient to use. Okish for certain usecases, but inconvenient or insufficient for more complicated usecases.

Alternatively, you could create your own rest services or prepare the data in the backend and write it into the content. e.g. write a portlet, that writes the data to the generated page.
thumbnail
Mahammad Ashik A, modified 6 Years ago. Junior Member Posts: 81 Join Date: 7/17/17 Recent Posts
Hi,

Could you please help me on this?

​​​​​​​Thank you
thumbnail
Christoph Rabel, modified 6 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Well, I really like to help, but I can't program that for you. I can point you to the interfaces you need, but I won't do all the work.