Skip to content
Snippets Groups Projects
Commit 8e3dad8b authored by Benjamin Ulrich's avatar Benjamin Ulrich :speech_balloon:
Browse files

Merge branch 'sales_2002515_districtdef_stackoverflow' into '2021.2'

Gebietsdefinition - Aktion Übergeordnetes Gebiet setzen: ein untergeordnetes...

See merge request xrm/basic!1589
parents a3d984c4 813a3e1b
No related branches found
No related tags found
No related merge requests found
import("system.result");
import("system.vars");
import("District_lib");
result.string(vars.get("$param.Ids_param"));
let roots = JSON.parse(vars.get("$param.Ids_param"));
result.string(JSON.stringify(DistrictUtils.getRecursiveChilds(roots)));
import("system.vars");
import("system.result");
import("system.vars");
import("District_lib");
var uid = vars.get("$field.DISTRICTID");
var res = JSON.stringify([uid]);
result.string(res);
\ No newline at end of file
let excluded = DistrictUtils.getRecursiveChilds([vars.get("$field.DISTRICTID")]);
result.string(JSON.stringify(excluded));
......@@ -469,6 +469,45 @@ DistrictUtils.setDistrictContactStatus = function (pArrIds, pStatus)
db.updates(updateArray);
}
/**
* Returns all recursive subitems (including itself) for all specified roots
*
* @param {String[]} pRoots the root disrict ids
*
* @returns all children (recursive)
*/
DistrictUtils.getRecursiveChilds = function(pRoots)
{
let data = newSelect(["DISTRICT.DISTRICTID", "DISTRICT.PARENTDISTRICT_DISTRICTID"]).from("DISTRICT").table();
let districtParentChildrenMap = new Map();
data.forEach(function([pIdentifier, pParent])
{
if(!pParent)
{
return;
}
if(!districtParentChildrenMap.has(pParent))
{
districtParentChildrenMap.set(pParent, []);
}
districtParentChildrenMap.get(pParent).push(pIdentifier);
});
// _traverseDistrictRootsRecursive is recursively called for every branch of subdistricts
let excludedDistrictIdentifierSet = new Set(pRoots);
function _traverseDistrictRootsRecursive(pRootsIterator)
{
pRootsIterator.forEach(function(pItem)
{
let childrenIterator = districtParentChildrenMap.get(pItem) || [];
childrenIterator.forEach(excludedDistrictIdentifierSet.add.bind(excludedDistrictIdentifierSet));
_traverseDistrictRootsRecursive(childrenIterator);
});
}
_traverseDistrictRootsRecursive(pRoots);
return Array.from(excludedDistrictIdentifierSet);
}
/*
* See DistrictChangeField_entity
*/
......
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