Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppPluginUtil;
import org.joget.apps.app.service.AppUtil;
import org.joget.plugin.base.ApplicationPlugin;
import org.joget.plugin.base.Plugin;
import org.joget.plugin.base.PluginManager;
import org.joget.plugin.property.model.PropertyEditable;
 
public Object execute(AppDefinition appDef, HttpServletRequest request) {
    String[] emails = new String[]{"test1@joget.org", "test2@joget.org"};
    
    //Reuse Email Tool to send separated email to a list of users;
    Plugin plugin = pluginManager.getPlugin("org.joget.apps.app.lib.EmailTool");
    
    //Get default properties (SMTP setting) for email tool
    Map propertiesMap = AppPluginUtil.getDefaultProperties(plugin, null, appDef, null);
    propertiesMap.put("pluginManager", pluginManager);
    propertiesMap.put("appDef", appDef);
    propertiesMap.put("request", request);
    
    ApplicationPlugin emailTool = (ApplicationPlugin) plugin;
    
    //send email
    for (String email : emails) {
        propertiesMap.put("toSpecific", email);
        propertiesMap.put("subject", "This is a test email for " + email);
        propertiesMap.put("message", "Email content for " + email);
        
        //set properties and execute the tool
        ((PropertyEditable) emailTool).setProperties(propertiesMap);
        emailTool.execute(propertiesMap);
    }
    
    return null;
}
 
//call execute method with injected variable
return execute(appDef, request);

Use as Datalist Action

Injected Variables:

    • httpRequest - HTTP Request object of current HTTP Request. (javax.servlet.http.HttpServletRequest)
    • datalist - Datalist object of the current datalist (org.joget.apps.datalist.model.Datalist)
    • rowKeys - A String array of record ID(s) for datalist row(s) that is selected for this action

Expected Return Object:

    • None

Samples:

Code Block
languagejava
for (String key : rowKeys) {
	System.out.println("Record key is " + key);
}

Use as Process Participant

Injected Variables:

    • pluginManager - Plugin Manager service bean for convenient usage. (org.joget.plugin.base.PluginManager)
    • workflowActivity - Workflow Activity that trying to retrieves assignee. (org.joget.workflow.model.WorkflowActivity)

Expected Return Object:

    • A java.util.Collection of username in java.lang.String to be assign to the Workflow Activity.

Samples:

        Randomly assign an user in a department to a workflow activity.

...

Use as Process Tool 
Anchor
Use as Process Tool
Use as Process Tool

Injected Variables:

    • workflowAssignment - The workflow tool activity assignment object. (org.joget.workflow.model.WorkflowAssignment)
    • pluginManager - Plugin Manager service bean for convenient usage. (org.joget.plugin.base.PluginManager)
    • appDef - App definition of the process. (org.joget.apps.app.model.AppDefinition)
    • request - Http Request object of current HTTP Request. Not available if the tool is trigger by Deadline. (javax.servlet.http.HttpServletRequest)

Expected Return Object:

    • None

Samples:

Start a new process in the same app with current record id.

...

Code Block
languagejava
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.app.service.AppUtil;
import org.joget.plugin.base.PluginManager;
import org.joget.apps.form.model.FormLoadBinder;
import org.joget.workflow.model.service.WorkflowManager;

    String formDefId = "ExpensesClaimEntry";  //change this to the form id used to load grid data
    String foreignKey = "claim"; //change this to the foreign key field id
      
    // Reuse Multi Row Binder to load data
    PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
    WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
    FormLoadBinder binder = (FormLoadBinder) pluginManager.getPlugin("org.joget.plugin.enterprise.MultirowFormBinder");
     
    //Load from the grid table
    binder.setProperty("formDefId", formDefId);
    binder.setProperty("foreignKey", foreignKey);
    
    FormRowSet rows;
    rows = binder.load(null, "#assignment.processId#", null);
    
	//loop through records returned
    for (FormRow row : rows) {
        try {
            Map variableMap = new HashMap();
            variableMap.put("status", row.getProperty("purpose"));
            
			//start a new process instance with data from each row
            //processStart(String processDefId, String processId, Map<String, String> variables, String startProcUsername, String parentProcessId, boolean startManually)
            workflowManager.processStart("expenseclaim:latest:process1", null, variableMap, null, row.getProperty("id"), false);
        } catch (Exception e) {}
    }

...


Use as Userview Permission

Injected Variables:

    • user - User object of current logged in user (org.joget.directory.model.User)
    • requestParams - Request parameters map of current HTTP Request (java.util.Map)

Expected Return Object:

    • A boolean value to indicate the user is authorized.

Samples:

Check the user is in a group and is an admin user.

...

...