How to get Processid from recorId Joget DX (Workflow) Plugin Datalist Action - Purwana Tekno, Software Engineer
    Media Belajar membuat Software Aplikasi, Website, Game, & Multimedia untuk Pemula...

Post Top Ad

Selasa, 09 Juli 2024

How to get Processid from recorId Joget DX (Workflow) Plugin Datalist Action

Untuk mendapatkan processId dari recordId di dalam Joget DX Plugin DataList Action, Anda perlu menulis custom code dalam plugin Anda. Joget Workflow menyediakan API untuk berinteraksi dengan database dan model data, yang dapat digunakan untuk mengambil processId berdasarkan recordId.


How to get Processid from recorId Joget DX (Workflow) Plugin Datalist Action - purwana.net


Berikut adalah contoh bagaimana Anda bisa melakukannya dalam Java:

Step-by-Step Guide:

Create a Custom DataList Action Plugin:

  • Implement DataListAction interface in your plugin class.
  • Override the necessary methods.

Fetch processId using recordId:

  • Use AppService or WorkflowManager to interact with the Joget database and retrieve the necessary information. Indonesia Raya Academy ~ Membangun Generasi Muda (Pariwisata & Perhotelan)

Sample Java Code:

Here's a simplified example of a custom DataList Action plugin that retrieves processId based on recordId:


package org.joget.plugin.custom;

import org.joget.apps.datalist.model.DataListAction;
import org.joget.apps.app.service.AppService;
import org.joget.workflow.model.WorkflowProcessLink;
import org.joget.workflow.model.service.WorkflowManager;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class CustomDataListAction extends DataListAction {
    
    @Override
    public String getName() {
        return "Custom Data List Action";
    }

    @Override
    public String getDescription() {
        return "A custom action to get processId from recordId.";
    }

    @Override
    public String getLabel() {
        return "Get Process ID";
    }

    @Override
    public String getLinkLabel() {
        return "Get Process ID";
    }

    @Override
    public void executeAction(DataList datalist, String[] rowIds) {
        if (rowIds != null && rowIds.length > 0) {
            for (String recordId : rowIds) {
                String processId = getProcessIdFromRecordId(recordId);
                if (processId != null) {
                    System.out.println("Process ID for record " + recordId + " is " + processId);
                    // You can perform further actions here based on the processId
                }
            }
        }
    }

   private String getProcessIdFromRecordId(String recordId) {
        ApplicationContext appContext = AppUtil.getApplicationContext();
        WorkflowManager workflowManager = (WorkflowManager) appContext.getBean("workflowManager");

        WorkflowProcessLink processLink = workflowManager.getWorkflowProcessLink(recordId);
        if (processLink != null) {
            return processLink.getProcessId();
        }
        return null;
    }
    
    @Override
    public String getClassName() {
        return getClass().getName();
    }

    @Override
    public String getPropertyOptions() {
        return "";
    }
}

Explanation:

ApplicationContext Retrieval:

  • AppUtil.getApplicationContext() is used to get the Spring application context.
  • From the application context, workflowManager bean is retrieved using appContext.getBean("workflowManager").

Workflow Manager Usage:

  • The getProcessIdFromRecordId method retrieves the WorkflowProcessLink object using the workflowManager and fetches the processId.

Logging:

  • LogUtil.info() is used to log the processId for each recordId. This can be replaced with any other action you want to perform with the processId.

Deployment:

  • Compile your Java code and package it as a JAR file.
  • Deploy the JAR file to Joget's wflow/app_plugins directory.
  • Restart the Joget server to load the new plugin.
  • Configure your DataList to use the new custom action.

This approach leverages the utility provided by Joget (AppUtil) to retrieve the application context and beans, ensuring that your plugin can interact with the necessary services without directly dealing with servlet context handling.


Post Top Ad