Skip to content
Snippets Groups Projects
Commit a0ac7d51 authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Marketing Workflow

parent 3229086b
No related branches found
No related tags found
No related merge requests found
Showing
with 310 additions and 94 deletions
......@@ -43,6 +43,10 @@
<name>Blacklist_param</name>
<valueProcess>%aditoprj%/entity/DocumentTemplatePlaceOfUse_entity/entityfields/contextdocumenttemplateplaceofuse/children/blacklist_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>GetAllContexts_param</name>
<valueProcess>%aditoprj%/entity/DocumentTemplatePlaceOfUse_entity/entityfields/contextdocumenttemplateplaceofuse/children/getallcontexts_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityProvider>
......
import("system.result");
result.object(["Person", "Organisation", "Offer"]);
\ No newline at end of file
result.object(["Person", "Organisation", "Offer", "MarketingWorkflowLauncher"]);
\ No newline at end of file
import("system.result");
result.string(true);
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.17" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.17">
<name>MarketingWorkflowLauncher_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<title>Marketing workflow</title>
<recordContainer>dataLess</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
</entityProvider>
<entityProvider>
<name>#PROVIDER_AGGREGATES</name>
<useAggregates v="true" />
</entityProvider>
<entityField>
<name>DOCUMENTTEMPLATE_ID</name>
<title>Document template</title>
<consumer>EmailTemplates</consumer>
<mandatory v="true" />
<state>EDITABLE</state>
</entityField>
<entityConsumer>
<name>WorkflowLauncherIntegration</name>
<isOneToOneRelationship v="true" />
<dependency>
<name>dependency</name>
<entityName>WorkflowLauncher_entity</entityName>
<fieldName>Integration</fieldName>
</dependency>
<children>
<entityParameter>
<name>Validationerrors_param</name>
<valueProcess>%aditoprj%/entity/MarketingWorkflowLauncher_entity/entityfields/workflowlauncherintegration/children/validationerrors_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>ProcessVariables_param</name>
<valueProcess>%aditoprj%/entity/MarketingWorkflowLauncher_entity/entityfields/workflowlauncherintegration/children/processvariables_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>Targets_param</name>
<valueProcess>%aditoprj%/entity/MarketingWorkflowLauncher_entity/entityfields/workflowlauncherintegration/children/targets_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>TargetContext_param</name>
<valueProcess>%aditoprj%/entity/MarketingWorkflowLauncher_entity/entityfields/workflowlauncherintegration/children/targetcontext_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityParameter>
<name>ObjectType_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>ObjectIds_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>ObjectFilter_param</name>
<expose v="true" />
</entityParameter>
<entityConsumer>
<name>EmailTemplates</name>
<dependency>
<name>dependency</name>
<entityName>DocumentTemplate_entity</entityName>
<fieldName>DocumentTemplateProvider</fieldName>
</dependency>
<children>
<entityParameter>
<name>DocumentTemplateType_param</name>
<valueProcess>%aditoprj%/entity/MarketingWorkflowLauncher_entity/entityfields/emailtemplates/children/documenttemplatetype_param/valueProcess.js</valueProcess>
</entityParameter>
<entityParameter>
<name>ComingFrom_param</name>
<valueProcess>%aditoprj%/entity/MarketingWorkflowLauncher_entity/entityfields/emailtemplates/children/comingfrom_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
</entityFields>
<recordContainers>
<datalessRecordContainer>
<name>dataLess</name>
</datalessRecordContainer>
</recordContainers>
</entity>
import("Context_lib");
import("system.result");
result.string(ContextUtils.getCurrentContextId());
\ No newline at end of file
import("system.result");
import("KeywordRegistry_basic");
result.string($KeywordRegistry.documentTemplateType$mail());
\ No newline at end of file
import("system.vars");
import("system.result");
var variables = {
documentTemplate: vars.get("$field.DOCUMENTTEMPLATE_ID")
};
result.string(JSON.stringify(variables));
\ No newline at end of file
import("Context_lib");
import("system.result");
result.string(ContextUtils.getCurrentContextId());
\ No newline at end of file
import("Util_lib");
import("system.vars");
import("system.result");
var context = vars.get("$param.ObjectType_param");
var targets = Utils.parseJSON(vars.get("$param.ObjectIds_param")) || [];
targets = targets.map(function (targetId)
{
if (Utils.isString(targetId))
return [targetId, context]; //todo: context dynamic (eg for participants)
return targetId;
});
result.string(JSON.stringify(targets));
\ No newline at end of file
import("system.vars");
import("system.result");
result.string(vars.get("$sys.validationerrors"));
\ No newline at end of file
......@@ -1097,6 +1097,12 @@
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Person_entity/entityfields/filterviewactiongroup/children/startmultipleworkflows/stateProcess.js</stateProcess>
</entityActionField>
<entityActionField>
<name>startMarketingWorkflows</name>
<title>Marketing Workflow</title>
<onActionProcess>%aditoprj%/entity/Person_entity/entityfields/filterviewactiongroup/children/startmarketingworkflows/onActionProcess.js</onActionProcess>
<isObjectAction v="false" />
</entityActionField>
</children>
</entityActionGroup>
<entityActionGroup>
......
import("Context_lib");
import("system.vars");
import("system.neon");
neon.openContext("MarketingWorkflowLauncher", "MarketingWorkflowLauncherEdit_view", null, neon.OPERATINGSTATE_VIEW, {
"ObjectIds_param": JSON.stringify(vars.get("$sys.selection")),
"ObjectType_param": ContextUtils.getCurrentContextId()
});
\ No newline at end of file
......@@ -22,6 +22,12 @@
<fieldName>WorkflowDefinitions</fieldName>
<isConsumer v="false" />
</entityDependency>
<entityDependency>
<name>8c60efea-5fa1-4df0-a6bb-9fadcc88554c</name>
<entityName>WorkflowLauncher_entity</entityName>
<fieldName>WorkflowDefinitions</fieldName>
<isConsumer v="false" />
</entityDependency>
</dependencies>
</entityProvider>
<entityField>
......
......@@ -120,10 +120,6 @@
<name>TargetContext_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>TargetIdFilter_param</name>
<expose v="true" />
</entityParameter>
<entityActionField>
<name>toggleActive</name>
<title>${WORKFLOW_SUSPEND}</title>
......@@ -211,7 +207,7 @@
<jDitoRecordContainer>
<name>jdito</name>
<isFilterable v="true" />
<isSortable v="true" />
<isSortable v="false" />
<contentProcess>%aditoprj%/entity/WorkflowInstance_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
<onInsert>%aditoprj%/entity/WorkflowInstance_entity/recordcontainers/jdito/onInsert.js</onInsert>
<onUpdate>%aditoprj%/entity/WorkflowInstance_entity/recordcontainers/jdito/onUpdate.js</onUpdate>
......
......@@ -27,12 +27,6 @@ if (idvalues)
loadHistoricConfig.processInstanceIds(idvalues);
historicInstances = JSON.parse(workflow.getHistoricProcessInstances(loadHistoricConfig));
}
//TODO: find a way the id can be gotten here
//after new-mode, only the workflow key is known, that means if with the given id
//no instance could be found, search with the key and use the item with the latest startTime
if (instances.length === 0 && historicInstances.length === 0)
instances = _getNewestInstanceForKey(idvalues[0]);
}
else
{
......@@ -78,25 +72,10 @@ historicInstances = historicInstances.map(function (instance)
return row;
});
instances = JditoFilterUtils.filterRecords(["UID", "NAME", "KEY", "ISACTIVE", "PROCESSDEFINITIONNAME", "PROCESSDEFINITION_ID", "START_TIME", "ISFINISHED"],
instances.concat(historicInstances), vars.get("$local.filter").filter);
result.object(instances);
function _getNewestInstanceForKey (pWorkflowKey)
{
var loadConfig = workflow.createConfigForLoadingProcessInstances()
.processDefinitionKey(pWorkflowKey);
var recordFilter = new JditoFilter()
.filter(vars.get("$local.filter"))
.fieldOrder(["UID", "NAME", "KEY", "ISACTIVE", "PROCESSDEFINITIONNAME", "PROCESSDEFINITION_ID", "START_TIME", "ISFINISHED"]);
var instances = JSON.parse(workflow.getProcessInstances(loadConfig));
if (instances.length === 0)
return [];
return [instances.reduce(function (prev, curr)
{
if (Date.parse(prev.startTime) > Date.parse(curr.startTime))
return prev;
return curr;
})];
}
\ No newline at end of file
instances = recordFilter.filterRecords(instances.concat(historicInstances));
result.object(instances);
\ No newline at end of file
import("system.neon");
import("Util_lib");
import("Employee_lib");
import("system.entities");
import("Context_lib");
import("Workflow_lib");
import("system.vars");
import("system.workflow");
import("system.process");
var variables = Utils.parseJSON(vars.getString("$param.ProcessVariables_param")) || {};
var targetIdFilter = Utils.parseJSON(vars.get("$param.TargetIdFilter_param"));
var rowdata = vars.get("$local.rowdata");
var processKey = rowdata["KEY.value"];
var instanceName = rowdata["NAME.value"];
......@@ -17,69 +15,23 @@ var startFormResult = Utils.parseJSON(rowdata["STARTFORMRESULT.value"]);
if (!Utils.isNullOrEmpty(startFormResult))
Object.assign(variables, startFormResult);
//a placeholder that can be used for individual instance names, will be replaced by the content title
var titlePlaceholder = "{title}";
var fetchContentTitle = instanceName && instanceName.includes(titlePlaceholder);
var targetId = variables[WorkflowVariables.TARGET_ID()];
var targetContext = variables[WorkflowVariables.TARGET_CONTEXT()];
var targetIds = [];
if (Array.isArray(targetId) && targetId.length !== 0)
{
targetIds = targetId.slice();
targetIdFilter = null;
}
else if (!Array.isArray(targetId) && targetId)
{
targetIds = [targetId];
targetIdFilter = null;
}
var targetContext = variables[WorkflowVariables.TARGET_CONTEXT()] || vars.get("$param.TargetContext_param");
if (targetIdFilter || fetchContentTitle)
//a placeholder that can be used for individual instance names, will be replaced by the content title
instanceName = instanceName.replace("{title}", function ()
{
var entity = ContextUtils.getEntity(targetContext);
var loadConfig = entities.createConfigForLoadingRows()
.entity(entity)
.fields(["#UID", "#CONTENTTITLE"]);
if (targetIdFilter && targetIdFilter.filter)
loadConfig.filter(JSON.stringify(targetIdFilter.filter));
else if (targetIds.length !== 0)
loadConfig.uids(targetIds);
var rowCount = entities.getRowCount(loadConfig);
var pageSize = 1000;
for (let startRow = 0; startRow < rowCount; startRow += pageSize)
{
loadConfig.startrow(startRow).count(pageSize);
let targetIdsAndNames = entities.getRows(loadConfig).map(function (row)
{
var name = instanceName;
if (fetchContentTitle)
name = name.replace(titlePlaceholder, row["#CONTENTTITLE"]);
return [row["#UID"], name];
});
_startForIds(targetIdsAndNames, variables);
}
.fields(["#CONTENTTITLE"])
.uid(targetId);
var row = entities.getRow(loadConfig);
//TODO: entities.getRows currently doesn't work on the server
// process.executeAsync("startWorkflowInstances_serverProcess", {
// processVariables : JSON.stringify(variables),
// processKey : processKey,
// entityFilter : targetIdFilter.filter ? JSON.stringify(targetIdFilter.filter) : ""
// }, false, EmployeeUtils.getCurrentUserName(), process.THREADPRIORITY_NORM, process.TIMERTYPE_SERVER);
}
else
_startForIds(targetIds.map(function (id) {return [id, instanceName];}), variables);
function _startForIds (pTargets, pVariables)
{
pTargets.forEach(function ([id, name])
{
pVariables[WorkflowVariables.TARGET_ID()] = id;
var instanceId = workflow.startProcessByKey(processKey, pVariables);
if (name)
workflow.setProcessInstanceName(instanceId, name);
});
}
return row && row["#CONTENTTITLE"] || "";
});
var instanceId = workflow.startProcessByKey(processKey, pVariables);
neon.setFieldValue("$field.UID", instanceId);
if (name)
workflow.setProcessInstanceName(instanceId, name);
<?xml version="1.0" encoding="UTF-8"?>
<entity xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.3.17" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/entity/1.3.17">
<name>WorkflowLauncher_entity</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<recordContainer>dataLess</recordContainer>
<entityFields>
<entityProvider>
<name>#PROVIDER</name>
</entityProvider>
<entityProvider>
<name>#PROVIDER_AGGREGATES</name>
<useAggregates v="true" />
</entityProvider>
<entityField>
<name>PROCESSDEFINITION_ID</name>
<valueProcess>%aditoprj%/entity/WorkflowLauncher_entity/entityfields/processdefinition_id/valueProcess.js</valueProcess>
</entityField>
<entityField>
<name>STARTFORMDEFINITION</name>
<valueProcess>%aditoprj%/entity/WorkflowLauncher_entity/entityfields/startformdefinition/valueProcess.js</valueProcess>
</entityField>
<entityField>
<name>STARTFORMRESULT</name>
</entityField>
<entityField>
<name>NAME</name>
<title>Name</title>
<state>EDITABLE</state>
</entityField>
<entityField>
<name>KEY</name>
<title>Key</title>
<consumer>WorkflowDefinitions</consumer>
<state>EDITABLE</state>
</entityField>
<entityActionField>
<name>launchWorkflows</name>
<title>Start workflows</title>
<onActionProcess>%aditoprj%/entity/WorkflowLauncher_entity/entityfields/launchworkflows/onActionProcess.js</onActionProcess>
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/WorkflowLauncher_entity/entityfields/launchworkflows/stateProcess.js</stateProcess>
</entityActionField>
<entityParameter>
<name>Targets_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>TargetFilter_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>ProcessVariables_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>TargetContext_param</name>
<expose v="true" />
</entityParameter>
<entityProvider>
<name>Integration</name>
</entityProvider>
<entityConsumer>
<name>WorkflowDefinitions</name>
<dependency>
<name>dependency</name>
<entityName>WorkflowDefinition_entity</entityName>
<fieldName>#PROVIDER</fieldName>
</dependency>
<children>
<entityParameter>
<name>Context_param</name>
<valueProcess>%aditoprj%/entity/WorkflowLauncher_entity/entityfields/workflowdefinitions/children/context_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityParameter>
<name>Validationerrors_param</name>
<expose v="true" />
</entityParameter>
<entityField>
<name>workflowCount</name>
</entityField>
<entityField>
<name>workflowTargets</name>
<valueProcess>%aditoprj%/entity/WorkflowLauncher_entity/entityfields/workflowtargets/valueProcess.js</valueProcess>
</entityField>
</entityFields>
<recordContainers>
<datalessRecordContainer>
<name>dataLess</name>
</datalessRecordContainer>
</recordContainers>
</entity>
import("system.neon");
import("Util_lib");
import("Workflow_lib");
import("system.vars");
import("system.workflow");
var variables = Utils.parseJSON(vars.get("$param.ProcessVariables_param")) || {};
var targets = Utils.parseJSON(vars.get("$field.workflowTargets")) || [];
var context = vars.get("$param.TargetContext_param");
var processKey = vars.get("$field.KEY");
var instanceName = vars.get("$field.NAME");
var startFormResult = Utils.parseJSON(vars.get("$field.STARTFORMRESULT"));
var instanceId;
if (!Utils.isNullOrEmpty(startFormResult))
Object.assign(variables, startFormResult);
targets.forEach(function ([targetId, targetContext, processVariables])
{
/* Caution: If 'variables' is used, then 'processVariables' is only a reference to 'variables'.
Currently that's fine, but keep it in mind when you change this code. */
if (!processVariables)
processVariables = variables;
processVariables[WorkflowVariables.TARGET_ID()] = targetId;
processVariables[WorkflowVariables.TARGET_CONTEXT()] = targetContext || context;
instanceId = workflow.startProcessByKey(processKey, processVariables);
if (instanceName)
workflow.setProcessInstanceName(instanceId, instanceName);
});
if (instanceId)
neon.openContext("WorkflowInstance", "WorkflowInstancePreview_view", [instanceId], neon.OPERATINGSTATE_VIEW, {});
\ No newline at end of file
import("system.vars");
import("system.result");
import("system.neon");
result.string(vars.get("$sys.validationerrors") || vars.get("$param.Validationerrors_param")
? neon.COMPONENTSTATE_DISABLED
: neon.COMPONENTSTATE_EDITABLE
);
\ No newline at end of file
import("system.vars");
import("system.result");
import("system.workflow");
var processKey = vars.get("$field.KEY");
if (processKey)
result.string(workflow.getLatestProcessDefinitionId(processKey));
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment