02-13-2013 05:08 PM
Branches —
AB —
10001 —
10002 —
…
CD —
200002 —
210001 —
…
EF —
…
Clients —
10001 —
10002 —
10003 —
….
function moveBranch() {
var notMovedClients = new Array();
var movedClients = new Array();
var branchid = url.templateArgs["branchid"]
if(branchid) {
try {
var branch = companyhome.childByNamePath("/Branches/" + branchid);
if(!branch) {
status.setCode(status.STATUS_OK, "Branch [" + branchid + "] does not exist. Nothing to do.");
return;
}
var clients = companyhome.childByNamePath("/Clients");
var remove = true;
var len = branch.children.length;
for(var i = 0; i < len; i++) {
var child = branch.children;
try {
if(clients.childByNamePath(child.name)) {
// Should not be required as move should return true or false.
// This does stop move throwing exceptions and causing the whole transaction to abort
remove = false;
notMovedClients.push(child.name);
continue;
}
var moved = child.move(clients);
if(!moved) {
remove = false;
notMovedClients.push(child.name);
} else {
movedClients.push(child.name);
}
}catch(e) {
// The move should not throw an exception but it does so catch it
// and treat it as a failure to move
remove = false;
notMovedClients.push(child.name);
}
}
if(remove) {
branch.remove();
}
var message = "Finished processing Branch [" + branchid + "].";
if(notMovedClients.length != 0) {
message += " The following clients were not able to be moved automatically and will need to be moved by hand [" + notMovedClients + "].";
}
if(movedClients.length != 0) {
message += " The follwing clients were moved [" + movedClients + "].";
}
status.setCode(status.STATUS_OK, message);
return;
}catch(e) {
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, e.toString());
return;
}
} else {
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Branch must be defined");
return;
}
}
moveBranch();
02-14-2013 03:54 AM
02-18-2013 05:01 PM
02-19-2013 04:18 AM
02-19-2013 04:50 PM
02-20-2013 06:40 PM
02-18-2013 05:09 PM
02-17-2013 06:02 PM
02-18-2013 05:05 PM
02-19-2013 01:39 AM
try {
var existingclient=clients.childByNamePath(child.name)
if(null!=existingclient) {
// Should not be required as move should return true or false.
// This does stop move throwing exceptions and causing the whole transaction to abort
remove = false;
notMovedClients.push(child.name);
continue;
}
else {
var moved = child.move(clients);
movedClients.push(child.name);
}
}catch(e) {
// The move should not throw an exception but it does so catch it
// and treat it as a failure to move
remove = false;
notMovedClients.push(child.name);
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.