如何在工作流脚本中获取Liferay动态数据列表RecordId(ddlRecordId)

如何在工作流脚本中获取Liferay动态数据列表RecordId(ddlRecordId),liferay,workflow,dynamic-data-list,Liferay,Workflow,Dynamic Data List,我正在尝试将Liferay动态数据列表集成到Kaleo工作流(Liferay 6.1 CE GA2)中,但是如何在工作流中获取ddlRecordId呢?我做了一些家庭作业,检查了serviceContext中的所有属性,但serviceContext属性中没有“ddlRecordId”,只有一个名为“recordId”的键,其值始终为0。此外,我还可以在serviceContext属性中获取一些字段值,例如select和textarea。但我想要的是上传文件字段。谢谢 long ddlRecor

我正在尝试将Liferay动态数据列表集成到Kaleo工作流(Liferay 6.1 CE GA2)中,但是如何在工作流中获取ddlRecordId呢?我做了一些家庭作业,检查了serviceContext中的所有属性,但serviceContext属性中没有“ddlRecordId”,只有一个名为“recordId”的键,其值始终为0。此外,我还可以在serviceContext属性中获取一些字段值,例如select和textarea。但我想要的是上传文件字段。谢谢

long ddlRecordId = GetterUtil.getLong(serviceContext.getAttribute("ddlRecordId"));
DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getRecord(ddlRecordId);

我也有同样的问题。我花了一个星期的时间试图解决这个问题,最后我终于明白了。 我希望它能解决你的问题

我必须恢复列表中的所有DDLRecords,并找到使用我的工作流的具有“recordSetId”属性的记录,与DDLRecord的“recordSetId”进行比较

最终代码如下所示:

import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.dynamicdatamapping.storage.Field;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
import com.liferay.portlet.dynamicdatalists.model.impl.DDLRecordImpl;
import com.liferay.portlet.dynamicdatalists.service.*;

long companyId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
String uuid = (String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID);

ServiceContext serviceContext = (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);

long ddlRecordId = GetterUtil.getLong(serviceContext.getAttribute("recordSetId"));
List ddlRecordList = DDLRecordLocalServiceUtil.getDDLRecords(0,DDLRecordLocalServiceUtil.getDDLRecordsCount());
for(DDLRecord o : ddlRecordList){
    if(o.getRecordSetId()==ddlRecordId){
        Field field = o.getField("status");

        String status = GetterUtil.getString(field.getValue());

        if (status.contains("not")) {
        returnValue = "No"
        }
        else {
        returnValue = "Yes"
        }
    }

}

在Liferay 6.1中,DDLRecordId相当于工作流上下文变量中的entryClassPK。这可能会有帮助(请阅读关于工作流上下文变量的部分)

因此,您可以通过以下方式获取上传文件字段:

import com.liferay.portlet.documentlibrary.store.DLStoreUtil;
import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
import com.liferay.portlet.dynamicdatamapping.storage.Field;
import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.util.GetterUtil;

import java.io.File;
import java.io.Serializable

DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getDDLRecord(GetterUtil.getLong(entryClassPK));
// get the upload field
Field field = ddlRecord.getField("field_attachment");
if (field != null){
    DDMStructure structure = field.getDDMStructure();
    Serializable fieldValue = field.getValue();
    String value = String.valueOf(fieldValue);
    if (!value.isEmpty()){
        JSONObject fileJSONObject = JSONFactoryUtil.createJSONObject(value);
        String fileName = fileJSONObject.getString("name");
        String filePath = fileJSONObject.getString("path");
        File file = DLStoreUtil.getFile(structure.getCompanyId(), 0L, filePath);
    }
}
我希望这将帮助不止一个