diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index bf4a87910fc9c95a5533dbfd7fec120fa0d71506..31c3172f84e785164019380de2f5e9d5315eb554 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -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> diff --git a/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js b/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js index fae54f62384d81d7bcb1f116cfe82ef470194ffc..4dd1c6ae0edb893438c881f315071acea64e8dcd 100644 --- a/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js +++ b/entity/Person_entity/entityfields/campaignactiongroup/children/startmultipleworkflows/onActionProcess.js @@ -1,4 +1,5 @@ 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 diff --git a/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js b/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js index 612fa49109ea606288ad2418e8bb7f9ce9f57316..2afd61402ee0fab203bf051660b1c227da1cdfdd 100644 --- a/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js +++ b/entity/WorkflowDefinition_entity/recordcontainers/jdito/onUpdate.js @@ -1,10 +1,19 @@ +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) {} +} diff --git a/entity/WorkflowInstance_entity/WorkflowInstance_entity.aod b/entity/WorkflowInstance_entity/WorkflowInstance_entity.aod index 2408a0b0d88507363f86534f0402f8d2afd1ed92..26156dbf3d70b8b9630bc74cd883cb87467cdf39 100644 --- a/entity/WorkflowInstance_entity/WorkflowInstance_entity.aod +++ b/entity/WorkflowInstance_entity/WorkflowInstance_entity.aod @@ -106,6 +106,10 @@ <name>TargetContext_param</name> <expose v="true" /> </entityParameter> + <entityParameter> + <name>TargetIdFilter_param</name> + <expose v="true" /> + </entityParameter> </entityFields> <recordContainers> <jDitoRecordContainer> diff --git a/entity/WorkflowInstance_entity/recordcontainers/jdito/contentProcess.js b/entity/WorkflowInstance_entity/recordcontainers/jdito/contentProcess.js index 44de4cc658e251d4b9a7324d4c6967f2a0964009..fa6930da974f88d066111b73f6a3345c788ae81d 100644 --- a/entity/WorkflowInstance_entity/recordcontainers/jdito/contentProcess.js +++ b/entity/WorkflowInstance_entity/recordcontainers/jdito/contentProcess.js @@ -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 diff --git a/entity/WorkflowInstance_entity/recordcontainers/jdito/onInsert.js b/entity/WorkflowInstance_entity/recordcontainers/jdito/onInsert.js index 07d29335208ccb4908b9699002f55d256c36e220..77082b126b1c1594a92029fe6b596c015a077046 100644 --- a/entity/WorkflowInstance_entity/recordcontainers/jdito/onInsert.js +++ b/entity/WorkflowInstance_entity/recordcontainers/jdito/onInsert.js @@ -1,16 +1,44 @@ +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); + }); +} + diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js index 000b21342c59c724b1fa38fcaf718ba4b5881c7d..1b910f2e34de1d8fb86377783028ebb0a25f17a3 100644 --- a/process/Context_lib/process.js +++ b/process/Context_lib/process.js @@ -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; } diff --git a/process/Workflow_lib/process.js b/process/Workflow_lib/process.js index 67b4340100ad618ec80c194e934d71b8eccbade7..ba2ff373f770cb2e8159d344f35454d95b6afa61 100644 --- a/process/Workflow_lib/process.js +++ b/process/Workflow_lib/process.js @@ -1,8 +1,10 @@ +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 || "" }); }