Skip to content
Snippets Groups Projects
Commit 5e6f9fda authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Merge branch '1059167_FixDeletePersonOnlyIfOneContact' into '2020.1'

[Projekt: Entwicklung - Neon][TicketNr.: 1059167][Kontakt/Firma: Kontakt mit...

See merge request xrm/basic!295
parents d1f9573d 3e25f85d
No related branches found
No related tags found
No related merge requests found
import("Sql_lib");
import("Entity_lib");
import("Employee_lib");
import("Context_lib");
import("system.vars");
import("system.result");
var contactId = vars.get("$field.CONTACTID");
var currentContext = ContextUtils.getCurrentContextId();
var canDelete = false;
var personId = vars.get("$field.PERSONID");
var personCount = newSelect("count(*)")
.from("CONTACT")
.join("PERSON", "PERSON.PERSONID = CONTACT.PERSON_ID")
.where("PERSON.PERSONID", personId)
.cell()
//only delete when the contact doesnt have any functions, because that would currently lead to the person and all his functions being deleted,
// since there is only one person contact behind all the contacts.
//ToDo: come back to this and implement the solution for deleting a function (#1059167) once it'S decided how that's being implemented
if(personCount == 1)
{
var contactId = vars.get("$field.CONTACTID");
var currentContext = ContextUtils.getCurrentContextId();
var canDelete = new HasLinkedObjectTester()
.andNoEntityRows("Activity_entity", "LinkedObjects", {ObjectId_param : currentContext, RowId_param : contactId}) //Activities
.andNoEntityRows("Task_entity", "Tasks", {ObjectId_param : currentContext, RowId_param : contactId}) //Tasks
.andNoEntityRows("Document_entity", "Documents", {AssignmentTable_param : "CONTACT", AssignmentRowId_param : contactId}) //Documents
.and(function () {return !EmployeeUtils.isUser(contactId);})
.andNoEntityRows("Offer_entity", "ContactOffers", {ContactId_param : contactId}) //Offers
.andNoEntityRows("Contract_entity", "Contracts", {ContactId_param : contactId}) //Contracts
.andNoEntityRows("ObjectTree_entity", "TreeProvider", {ObjectIds_param : JSON.stringify([contactId, vars.get("$field.PERSON_ID")]), ObjectTypes_param : JSON.stringify([currentContext, "PrivatePerson"])})
.validate();
canDelete = new HasLinkedObjectTester()
.andNoEntityRows("Activity_entity", "LinkedObjects", {ObjectId_param : currentContext, RowId_param : contactId}) //Activities
.andNoEntityRows("Task_entity", "Tasks", {ObjectId_param : currentContext, RowId_param : contactId}) //Tasks
.andNoEntityRows("Document_entity", "Documents", {AssignmentTable_param : "CONTACT", AssignmentRowId_param : contactId}) //Documents
.and(function () {return !EmployeeUtils.isUser(contactId);})
.andNoEntityRows("Offer_entity", "ContactOffers", {ContactId_param : contactId}) //Offers
.andNoEntityRows("Contract_entity", "Contracts", {ContactId_param : contactId}) //Contracts
.andNoEntityRows("ObjectTree_entity", "TreeProvider", {ObjectIds_param : JSON.stringify([contactId, vars.get("$field.PERSON_ID")]), ObjectTypes_param : JSON.stringify([currentContext, "PrivatePerson"])})
.validate();
}
result.string(canDelete);
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