Skip to content
Snippets Groups Projects
Commit a8a91802 authored by S.Listl's avatar S.Listl
Browse files

Workflow start with selection, editing fix

parent 0c3a5968
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
<title>Start workflow</title>
<onActionProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js</onActionProcess>
<isObjectAction v="false" />
<isSelectionAction v="true" />
<iconId>VAADIN:PLAY</iconId>
<stateProcess>%aditoprj%/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/stateProcess.js</stateProcess>
</entityActionField>
......
import("system.vars");
import("Workflow_lib");
import("system.entities");
WorkflowUtils.openNewInstance(null, vars.get("$sys.selection"));
\ No newline at end of file
WorkflowUtils.openNewInstance(null, vars.get("$sys.selection"), undefined, vars.get("$sys.filter"));
\ No newline at end of file
import("system.util");
import("system.vars");
import("system.workflow");
import("Document_lib");
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")
workflow.setProcessActive(rowdata["UID.value"], rowdata["ISACTIVE.value"] == "true");
});
\ No newline at end of file
//the xml could be invalid
try {
workflow.deployProcess(rowdata["KEY.value"], upload.getBase64DecodedData());
} catch (ex) {}
}
......@@ -106,6 +106,10 @@
<name>TargetContext_param</name>
<expose v="true" />
</entityParameter>
<entityParameter>
<name>TargetIdFilter_param</name>
<expose v="true" />
</entityParameter>
</entityFields>
<recordContainers>
<jDitoRecordContainer>
......
......@@ -23,12 +23,18 @@ if (idvalues)
//no instance could be found, search with the key and use the item with the latest startTime
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))
return prev;
return curr;
})];
wfInstances = [instances.reduce(function (prev, curr)
{
if (Date.parse(prev.startTime) > Date.parse(curr.startTime))
return prev;
return curr;
})];
}
}
}
else
......
import("system.entities");
import("Context_lib");
import("Workflow_lib");
import("system.vars");
import("system.workflow");
import("system.process");
var variables = JSON.parse(vars.getString("$param.ProcessVariables_param"));
var targetIds;
if (Array.isArray(variables.targetId))
targetIds = variables.targetId.slice();
var targetIdFilter = vars.get("$param.TargetIdFilter_param") ? JSON.parse(vars.getString("$param.TargetIdFilter_param")) : null;
var processKey = vars.get("$local.rowdata")["KEY.value"];
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
targetIds = [variables.targetId];
_startForIds([variables.targetId], variables);
targetIds.forEach(function (id)
function _startForIds (pTargetIds, pVariables)
{
variables.targetId = id;
workflow.startProcessByKey(vars.get("$local.rowdata")["KEY.value"], variables);
});
pTargetIds.forEach(function (id)
{
pVariables.targetId = id;
workflow.startProcessByKey(processKey, pVariables);
});
}
......@@ -57,6 +57,17 @@ ContextUtils.getIcon = function(pContextId)
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
*
......@@ -67,8 +78,7 @@ ContextUtils.getIcon = function(pContextId)
*/
ContextUtils.getEntityTitle = function (pContextId, pTranslate)
{
var entity = project.getContextStructure(pContextId).entity;
var title = project.getDataModel(project.DATAMODEL_KIND_ENTITY, entity)[1];
var title = project.getDataModel(project.DATAMODEL_KIND_ENTITY, ContextUtils.getEntity(pContextId))[1];
return pTranslate ? translate.text(title) : title;
}
......
import("system.logging");
import("system.project");
import("Sql_lib");
import("system.neon");
import("Context_lib");
import("system.vars");
import("system.entities");
import("system.workflow");
import("KeywordRegistry_basic");
......@@ -33,14 +35,22 @@ WorkflowUtils.getPossibleWorkflowDefinitions = function (pContext, pAction)
* @param {Object} [pVariables] variables for the process instance
* @param {String} [pTargetId=$sys.uid] uid of the target object
* @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, {
"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