Skip to content
Snippets Groups Projects
Commit fd20badc authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

Merge branch 'Dependency_WorkflowExtentions' into 'master'

Dependency_WorkflowExtentions

See merge request xrm/basic!489
parents f3915960 9a0d526c
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,27 @@ ContextUtils.getEntity = function (pContextId)
return project.getContextStructure(pContextId).entity;
}
/**
* Returns the context associated with the entity
*
* @param {String} pEntity the name of the Entity
* @return {String} the context
*/
ContextUtils.getContextId = function (pEntity)
{
if (!pEntity)
return null;
let contexte = ContextUtils.getContexts(false, [], false);
for (let i = 0; i < contexte.length; i++) {
if (ContextUtils.getEntity(contexte[i][0]) == pEntity)
return contexte[i][0];
}
return null;
}
/**
* Returns the title of the entity associated with the context
*
......
......@@ -29,6 +29,9 @@ Dependency.mapping = function ()
return {
"Address_entity": {
"Organisation_entity" : {
"options" : {
"isObservable" : true
},
"getUIDsfn" : function (pRowData, pChangedData) {
var tableField = "ADDRESS.CONTACT_ID";
var res = [];
......@@ -47,12 +50,26 @@ Dependency.mapping = function ()
* Returns the dependencies on the entity
*
* @param {String} [pEntity] the name of the entity
* @param {Object} [pOptionFilter] the Object must be handed over in the format: { "option" : true/false }
*
* @example
* Dependency.getDependency("Organisation_entity", {"isObservable" : true });
* @example
* Dependency.getDependency("Organisation_entity", {}));
* @example
* Dependency.getDependency("Organisation_entity"));
*
* @return {String[]} the founded Dependencies. If no one is found, you get an empty Array
*/
Dependency.getDependency = function (pEntity) {
Dependency.getDependency = function (pEntity, pOptionFilter) {
if (Dependency.mapping()[pEntity])
{
return Object.keys(Dependency.mapping()[pEntity]);
return Object.keys(Dependency.mapping()[pEntity]).filter(function (key) {
return (!pOptionFilter || Object.keys(pOptionFilter).every(function (pOption) {
let option = Dependency.mapping()[pEntity][key]["options"][pOption]
return option && pOptionFilter[pOption] == option;
}));
});
}
......@@ -63,10 +80,24 @@ Dependency.getDependency = function (pEntity) {
* Returns the dependencies that this entity has on others
*
* @param {String} [pEntity] the name of the entity
* @param {Object} [pOptionFilter] the Object must be handed over in the format: { "option" : true/false }
*
* @example
* Dependency.getReverseDependency("Organisation_entity", {"isObservable" : true });
* @example
* Dependency.getReverseDependency("Organisation_entity", {}));
* @example
* Dependency.getReverseDependency("Organisation_entity"));
*
* @return {String[]} the founded Dependencies. If no one is found, you get an empty Array
*/
Dependency.getReverseDependency = function (pEntity) {
Dependency.getReverseDependency = function (pEntity, pOptionFilter) {
return Object.keys(Dependency.mapping()).filter(function (key) {
return Dependency.mapping()[key][pEntity];
return Dependency.mapping()[key][pEntity] && (!pOptionFilter || Object.keys(pOptionFilter).every(function (pOption){
let option = Dependency.mapping()[key][pEntity]["options"][pOption]
return option && pOptionFilter[pOption] == option;
}));
});
}
import("Employee_lib");
import("system.process");
import("Util_lib");
import("system.text");
......@@ -46,18 +47,15 @@ WorkflowUtils.openNewInstance = function (pVariables, pTargetIds, pTargetContext
{
if ((!pTargetIds || pTargetIds.length === 0) && pSelectionFilter)
pTargetIds = [];
else if (!pTargetIds)
pTargetIds = [WorkflowVariables.TARGET_ID.getDefaultValue()];
if (!pVariables)
pVariables = {};
Object.assign(pVariables, WorkflowVariables.getTargetVariables(pTargetIds, pTargetContext));
neon.openContext("WorkflowLauncher", "WorkflowLauncherEdit_view", null, neon.OPERATINGSTATE_VIEW, {
"ProcessVariables_param": JSON.stringify(pVariables),
"TargetContext_param": pVariables[WorkflowVariables.TARGET_CONTEXT()],
"TargetFilter_param": pSelectionFilter ? JSON.stringify(pSelectionFilter) : "",
"Targets_param": JSON.stringify(pTargetIds)
"ProcessVariables_param" : JSON.stringify(pVariables),
"TargetContext_param" : pVariables[WorkflowVariables.TARGET_CONTEXT()],
"TargetFilter_param" : pSelectionFilter ? JSON.stringify(pSelectionFilter) : ""
});
}
......@@ -176,7 +174,19 @@ WorkflowSignalSender.deleted = function (pVariables, pTargetId, pTargetContext)
*/
WorkflowSignalSender.eventHappened = function (pEvent, pTargetId, pTargetContext, pVariables)
{
var variables = WorkflowVariables.getTargetVariables(pTargetId, pTargetContext);
let temp = {};
temp[ WorkflowVariables.TARGET_CONTEXT()] = pTargetContext;
temp[WorkflowVariables.TARGET_ID()] = pTargetId;
temp[WorkflowVariables.TRIGGER()] = pEvent;
let variables = WorkflowVariables.getAllVariablesValue(temp);
var processConfig = process.createStartAsyncConfig().setName("workflowExtension_serverProcess")
.setLocalVariables({"variablesWorkflow" : JSON.stringify(variables)})
.setShowErrorDialog(true)
.setUser(vars.get("sys.user"))
.setThreadPriority(process.THREADPRIORITY_NORM)
.setTimerType(process.TIMERTYPE_SERVER);
process.startAsync(processConfig);
var signals = WorkflowSignalSender.getSignalConfig(variables[WorkflowVariables.TARGET_CONTEXT()], pEvent);
signals.forEach(function (signal)
......@@ -281,6 +291,160 @@ WorkflowVariables.TARGET_CONTEXT.getDefaultValue = function ()
return ContextUtils.getCurrentContextId();
}
/**
* Returns the variable name for the rowdata
*/
WorkflowVariables.ROWDATA = function ()
{
return "rowdata";
}
/**
* Returns the default value for the rowdata
*/
WorkflowVariables.ROWDATA.getDefaultValue = function ()
{
return JSON.stringify(vars.get("$local.rowdata"));
}
/**
* Returns the variable name for the changed rows
*/
WorkflowVariables.CHANGED_ROWS = function ()
{
return "changedRows";
}
/**
* Returns the default value for the changed rows
*/
WorkflowVariables.CHANGED_ROWS.getDefaultValue = function ()
{
return JSON.stringify(vars.get("$local.changed"));
}
/**
* Returns the variable name for the event user
*/
WorkflowVariables.EVENT_USER = function ()
{
return "eventUser";
}
/**
* Returns the default value for the event user
*/
WorkflowVariables.EVENT_USER.getDefaultValue = function ()
{
return EmployeeUtils.getCurrentUserId();
}
/**
* Returns the variable name for the event time
*/
WorkflowVariables.EVENT_TIME = function ()
{
return "eventTime";
}
/**
* Returns the default value for the event time
*/
WorkflowVariables.EVENT_TIME.getDefaultValue = function ()
{
return vars.get("$sys.date");
}
/**
* Returns the variable name for the trigger
*/
WorkflowVariables.TRIGGER = function ()
{
return "trigger";
}
/**
* Returns the default value for the trigger
*/
WorkflowVariables.TRIGGER.getDefaultValue = function ()
{
return null;
}
/**
* Returns the variable name for the contenttitle
*/
WorkflowVariables.CONTENTTITLE = function ()
{
return "contenttitle";
}
/**
* Returns the default value for the contenttitle
*/
WorkflowVariables.CONTENTTITLE.getDefaultValue = function ()
{
return vars.get("$field.#CONTENTTITLE");
}
/**
* Returns an array of the WorkflowVariables
*
* @return {Array} array containing the variables name
*/
WorkflowVariables.getAllVariablesName = function ()
{
return [
WorkflowVariables.TARGET_CONTEXT(),
WorkflowVariables.TARGET_ID()
]
}
/**
* Returns an array of the Variables, which contains the variables name
*
* @return {Array} array containing the variables
*/
WorkflowVariables.getAllVariables = function ()
{
return [
"CHANGED_ROWS",
"EVENT_TIME",
"EVENT_USER",
"ROWDATA",
"TARGET_CONTEXT",
"TARGET_ID",
"TRIGGER",
"CONTENTTITLE"
]
}
/**
* Makes an object containing the variables
*
* @param {Objcet} [pVariables] value for the variables, if not provided, the dafault value is used.
* The Object have to hand over in the following format:
*
* {WorkflowVariable : value}
*
* @return {Object} object containing the variables
*/
WorkflowVariables.getAllVariablesValue = function (pVariables)
{
if (!pVariables)
pVariables = {};
let tempVariables = {};
WorkflowVariables.getAllVariables().forEach(function (v){
let tempName = WorkflowVariables[v]();
if (pVariables[tempName])
tempVariables[tempName] = pVariables[tempName]
else
tempVariables[tempName] = WorkflowVariables[v].getDefaultValue();
});
return tempVariables;
}
/**
* Makes an object containing the variables "targetId" and "targetContext"
*
......
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1">
<name>workflowExtension_serverProcess</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<process>%aditoprj%/process/workflowExtension_serverProcess/process.js</process>
<variants>
<element>EXECUTABLE</element>
</variants>
</process>
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