Foros de discusión

How do I get DDLRecords field values in Liferay 7?

thumbnail
Ravi Rupapara, modificado hace 6 años.

How do I get DDLRecords field values in Liferay 7?

New Member Mensajes: 9 Fecha de incorporación: 28/07/16 Mensajes recientes
I want to access the DDLRecords fields and values.
Below is my controller code with few tries. there is no any method like questionRecord.getFieldValue("field")

List<ddlrecord> records = DDLRecordLocalServiceUtil.getRecords(recordSetId, WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    for (DDLRecord questionRecord : records) {
      try {
        log.info(questionRecord.getFieldType("SalesforceFieldName").toString());
        log.info(questionRecord.getDDMStorageId());
        questionRecord.getDDMFormFieldValues(fieldName);
        log.info(DDMContentLocalServiceUtil.getContent(questionRecord.getDDMStorageId()).getData());
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }</ddlrecord>
thumbnail
Ravi Rupapara, modificado hace 6 años.

RE: How do I get DDLRecords field values in Liferay 7? (Respuesta)

New Member Mensajes: 9 Fecha de incorporación: 28/07/16 Mensajes recientes
I got the solution.

you need to use DDLDisplayTemplateHelper to extract the field values from DDLRecord.

DDLDisplayTemplateHelper is not avalibale directly, you need to export below package com.liferay.dynamic.data.lists.web.internal.template from your existing Liferay Dynamic Data Lists Web (1.1.23)

For that, you need to download respective versions source code from https://github.com/liferay/com-liferay-dynamic-data-lists
and add com.liferay.dynamic.data.lists.web.internal.template to export package of dynamic-data-lists-web sub module
build and deploy you will have access of DDLDisplayTemplateHelper in your module

Add the following dependency in your gradle file
compile group: "com.liferay", name: "com.liferay.dynamic.data.lists.api", version: "2.1.2"
compile group: 'com.liferay', name: 'com.liferay.dynamic.data.lists.web', version: '1.1.23'
compile group: "com.liferay", name: "com.liferay.dynamic.data.mapping.api", version: "3.5.5"


Usage:

import com.liferay.dynamic.data.lists.constants.DDLWebKeys;
import com.liferay.dynamic.data.lists.model.DDLRecord;
import com.liferay.dynamic.data.lists.model.DDLRecordSet;
import com.liferay.dynamic.data.lists.service.DDLRecordLocalServiceUtil;
import com.liferay.dynamic.data.lists.service.DDLRecordSetLocalServiceUtil;
import com.liferay.dynamic.data.lists.web.internal.template.DDLDisplayTemplateHelper;

DDLDisplayTemplateHelper.renderRecordFieldValue(questionRecord.getDDMFormFieldValues("FieldName").get(0), Locale.US)

Parth Pancholi, modificado hace 6 años.

RE: How do I get DDLRecords field values in Liferay 7?

New Member Mensajes: 2 Fecha de incorporación: 20/10/15 Mensajes recientes
We do not need to change any of the internal of the Liferay to get the data from DDLList.
We can use below code to get the data for the particular field in DDL.


DDLRecordLocalServiceUtil.getRecords(<<RedordId>>).parallelStream().forEach(ddlRecord -> {
try {
ddlRecord.getDDMFormFieldValues(<<FieldName>>).parallelStream().forEach(val -> {
System.out.println(val.getValue().getString(val.getValue().getDefaultLocale()));
});
} catch (PortalException e) {
e.printStackTrace();
}
});