Skip to content
Snippets Groups Projects
Commit 3e49af32 authored by S.Listl's avatar S.Listl Committed by Sebastian Listl
Browse files

Workflow start with selection, editing fix

(cherry picked from commit a8a91802)
parent 75204aeb
No related branches found
No related tags found
No related merge requests found
...@@ -1033,7 +1033,6 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact ...@@ -1033,7 +1033,6 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact
<title>Start workflow</title> <title>Start workflow</title>
<onActionProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js</onActionProcess> <onActionProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js</onActionProcess>
<isObjectAction v="false" /> <isObjectAction v="false" />
<isSelectionAction v="true" />
<iconId>VAADIN:PLAY</iconId> <iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/stateProcess.js</stateProcess> <stateProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/stateProcess.js</stateProcess>
</entityActionField> </entityActionField>
......
import("system.vars"); import("system.vars");
import("Workflow_lib"); import("Workflow_lib");
import("system.entities");
WorkflowUtils.openNewInstance(null, vars.get("$sys.selection")); WorkflowUtils.openNewInstance(null, vars.get("$sys.selection"), undefined, vars.get("$sys.filter"));
\ No newline at end of file \ No newline at end of file
import("system.util");
import("system.vars"); import("system.vars");
import("system.workflow"); import("system.workflow");
import("Document_lib");
var rowdata = vars.get("$local.rowdata"); var rowdata = vars.get("$local.rowdata");
vars.get("$local.changed").forEach(function (field) if (vars.get("$local.changed").indexOf("ISACTIVE.value") !== -1)
workflow.setProcessActive(rowdata["UID.value"], rowdata["ISACTIVE.value"] == "true");
var upload = new FileUpload(vars.get("$field.FILEUPLOAD"));
if (upload.isFilled())
{ {
if (field == "ISACTIVE.value") //the xml could be invalid
workflow.setProcessActive(rowdata["UID.value"], rowdata["ISACTIVE.value"] == "true"); try {
}); workflow.deployProcess(rowdata["KEY.value"], upload.getBase64DecodedData());
\ No newline at end of file } catch (ex) {}
}
...@@ -106,6 +106,10 @@ ...@@ -106,6 +106,10 @@
<name>TargetContext_param</name> <name>TargetContext_param</name>
<expose v="true" /> <expose v="true" />
</entityParameter> </entityParameter>
<entityParameter>
<name>TargetIdFilter_param</name>
<expose v="true" />
</entityParameter>
</entityFields> </entityFields>
<recordContainers> <recordContainers>
<jDitoRecordContainer> <jDitoRecordContainer>
......
...@@ -23,12 +23,18 @@ if (idvalues) ...@@ -23,12 +23,18 @@ if (idvalues)
//no instance could be found, search with the key and use the item with the latest startTime //no instance could be found, search with the key and use the item with the latest startTime
if (wfInstances.length === 0) if (wfInstances.length === 0)
{ {
wfInstances = [_getInstances(null, idvalues[0]).reduce(function (prev, curr) var instances = _getInstances(null, idvalues[0]);
if (instances.length === 0)
wfInstances = [];
else
{ {
if (Date.parse(prev.startTime) > Date.parse(curr.startTime)) wfInstances = [instances.reduce(function (prev, curr)
return prev; {
return curr; if (Date.parse(prev.startTime) > Date.parse(curr.startTime))
})]; return prev;
return curr;
})];
}
} }
} }
else else
......
import("system.entities");
import("Context_lib");
import("Workflow_lib"); import("Workflow_lib");
import("system.vars"); import("system.vars");
import("system.workflow"); import("system.workflow");
import("system.process");
var variables = JSON.parse(vars.getString("$param.ProcessVariables_param")); var variables = JSON.parse(vars.getString("$param.ProcessVariables_param"));
var targetIds; var targetIdFilter = vars.get("$param.TargetIdFilter_param") ? JSON.parse(vars.getString("$param.TargetIdFilter_param")) : null;
if (Array.isArray(variables.targetId)) var processKey = vars.get("$local.rowdata")["KEY.value"];
targetIds = variables.targetId.slice();
if (targetIdFilter)
{
var entity = ContextUtils.getEntity(variables.targetContext);
var loadConfig = entities.createConfigForLoadingRows()
.entity(entity)
.fields(["#UID"]);
if (targetIdFilter.filter)
loadConfig.filter(JSON.stringify(targetIdFilter.filter));
var rowCount = entities.getRowCount(loadConfig);
var pageSize = 400;
for (let startRow = 0; startRow < rowCount; startRow += pageSize)
{
loadConfig.startrow(startRow).count(pageSize);
let targetIds = entities.getRows(loadConfig).map(function (row) {return row["#UID"];});
_startForIds(targetIds, variables);
}
}
else if (Array.isArray(variables.targetId))
_startForIds(variables.targetId.slice(), variables);
else else
targetIds = [variables.targetId]; _startForIds([variables.targetId], variables);
targetIds.forEach(function (id) function _startForIds (pTargetIds, pVariables)
{ {
variables.targetId = id; pTargetIds.forEach(function (id)
workflow.startProcessByKey(vars.get("$local.rowdata")["KEY.value"], variables); {
}); pVariables.targetId = id;
workflow.startProcessByKey(processKey, pVariables);
});
}
...@@ -57,6 +57,17 @@ ContextUtils.getIcon = function(pContextId) ...@@ -57,6 +57,17 @@ ContextUtils.getIcon = function(pContextId)
return project.getDataModel(project.DATAMODEL_KIND_CONTEXT, pContextId)[5]; return project.getDataModel(project.DATAMODEL_KIND_CONTEXT, pContextId)[5];
} }
/**
* Returns the entity associated with the context
*
* @param {String} pContextId id of the context
* @return {String} the entity
*/
ContextUtils.getEntity = function (pContextId)
{
return project.getContextStructure(pContextId).entity;
}
/** /**
* Returns the title of the entity associated with the context * Returns the title of the entity associated with the context
* *
...@@ -67,8 +78,7 @@ ContextUtils.getIcon = function(pContextId) ...@@ -67,8 +78,7 @@ ContextUtils.getIcon = function(pContextId)
*/ */
ContextUtils.getEntityTitle = function (pContextId, pTranslate) ContextUtils.getEntityTitle = function (pContextId, pTranslate)
{ {
var entity = project.getContextStructure(pContextId).entity; var title = project.getDataModel(project.DATAMODEL_KIND_ENTITY, ContextUtils.getEntity(pContextId))[1];
var title = project.getDataModel(project.DATAMODEL_KIND_ENTITY, entity)[1];
return pTranslate ? translate.text(title) : title; return pTranslate ? translate.text(title) : title;
} }
......
import("system.logging");
import("system.project"); import("system.project");
import("Sql_lib"); import("Sql_lib");
import("system.neon"); import("system.neon");
import("Context_lib"); import("Context_lib");
import("system.vars"); import("system.vars");
import("system.entities");
import("system.workflow"); import("system.workflow");
import("KeywordRegistry_basic"); import("KeywordRegistry_basic");
...@@ -33,14 +35,22 @@ WorkflowUtils.getPossibleWorkflowDefinitions = function (pContext, pAction) ...@@ -33,14 +35,22 @@ WorkflowUtils.getPossibleWorkflowDefinitions = function (pContext, pAction)
* @param {Object} [pVariables] variables for the process instance * @param {Object} [pVariables] variables for the process instance
* @param {String} [pTargetId=$sys.uid] uid of the target object * @param {String} [pTargetId=$sys.uid] uid of the target object
* @param {String} [pTargetContext=current context] target context * @param {String} [pTargetContext=current context] target context
* @param {String} [pSelectionFilter] filter
*/ */
WorkflowUtils.openNewInstance = function (pVariables, pTargetId, pTargetContext) WorkflowUtils.openNewInstance = function (pVariables, pTargetId, pTargetContext, pSelectionFilter)
{ {
pVariables = WorkflowUtils.appendMandatoryVariables(pVariables, pTargetId, pTargetContext) if ((!pTargetId || pTargetId.length === 0) && pSelectionFilter)
{
pTargetId = [];
pSelectionFilter = JSON.stringify(pSelectionFilter);
}
pVariables = WorkflowUtils.appendMandatoryVariables(pVariables, pTargetId, pTargetContext);
neon.openContext("WorkflowInstance", null, null, neon.OPERATINGSTATE_NEW, { neon.openContext("WorkflowInstance", null, null, neon.OPERATINGSTATE_NEW, {
"ProcessVariables_param" : JSON.stringify(pVariables), "ProcessVariables_param" : JSON.stringify(pVariables),
"TargetContext_param" : pVariables.targetContext "TargetContext_param" : pVariables.targetContext,
"TargetIdFilter_param" : pSelectionFilter || ""
}); });
} }
......
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