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

prevent duplicate contacts (same ORGANISATION and PERSON) (2)

parent dc7c57f8
No related branches found
No related tags found
No related merge requests found
import("Contact_lib");
import("system.translate");
import("system.result");
import("system.db");
......@@ -14,17 +15,8 @@ var organisationId = ProcessHandlingUtils.getOnValidationValue("$field.ORGANISAT
//TODO: change the workaround behaviour when $local.value is retrieved correct
organisationId = vars.getString("$field.ORGANISATION_ID");
if (personId)
{
if (organisationId == "")
organisationId = "0";
var alreadyExistantContactId = db.cell(SqlCondition.begin()
.andPrepare("CONTACT.PERSON_ID", personId)
.andPrepare("CONTACT.ORGANISATION_ID", organisationId)
.buildSql("select CONTACT.CONTACTID from CONTACT"));
if (alreadyExistantContactId != "")
if (organisationId.trim() == "0")
result.string(translate.text("This private person doeas already exist and can not be created once more."));
else
result.string(translate.text("This combination of person and organisation does already exist and can not be created once more."));
}
\ No newline at end of file
//a entry within the Contact_enity can never be edited only created (it's edited within the Person_entity)
//so no need to provide our own CONTACTID since it does not exist in the database right now => provide null instead
var validationMsg = ContactUtils.validateIfAlreadyExists(personId, organisationId, null);
if (validationMsg)
result.string(validationMsg);
\ No newline at end of file
import("system.logging");
import("system.translate");
import("system.result");
import("system.db");
import("system.vars");
import("system.neon");
import("system.vars");
import("Entity_lib");
import("Contact_lib");
import("Sql_lib");
//TODO: comment
//TODO: into lib
//TODO: use in Contact
ContactUtils.validateOrganisationId = function(pPersonId, pOrganisationId, pOwnContactId)
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_NEW)
{
if (!pPersonId)
return null;
if (pOrganisationId == "")
pOrganisationId = "0";
var cond = SqlCondition.begin()
.andPrepare("CONTACT.PERSON_ID", pPersonId)
.andPrepare("CONTACT.ORGANISATION_ID", pOrganisationId)
//exclude the own since we do not want a "is not valid"-message for our own entry (on EDIT-mode)
.andPrepareIfSet("CONTACT.CONTACTID", pOwnContactId, "# != ?");
var sql = cond.buildSql("select CONTACT.CONTACTID from CONTACT");
var alreadyExistantContactId = db.cell(sql);
if (alreadyExistantContactId)
if (pOrganisationId.trim() == "0")
return translate.text("This private person doeas already exist and can not be created once more.");
else
return translate.text("This combination of person and organisation does already exist and can not be created once more.");
var personId = vars.getString("$field.PERSONID");
var organisationId = ProcessHandlingUtils.getOnValidationValue("$field.ORGANISATION_ID");
var contactId = vars.get("$field.CONTACTID");//in EDIT we have to exclude our own CONTACTID since we do not want a message for our own contactentry
return null;
};
var personId = vars.getString("$field.PERSONID");
var organisationId = ProcessHandlingUtils.getOnValidationValue("$field.ORGANISATION_ID");
var contactId;//in EDIT we have to exclude our own CONTACTID since we do not want a message for our own contactentry
if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_NEW)
contactId = vars.get("$field.CONTACTID");
//workaround for organisationId: $local.value will return the name of the organisation which is not what we want
//but the field already contains the changed value; so let's load the field instead of the $local.value-variable
//this is a bug within the ADITO-kernel
//TODO: change the workaround behaviour when $local.value is retrieved correct
organisationId = vars.getString("$field.ORGANISATION_ID");
//workaround for organisationId: $local.value will return the name of the organisation which is not what we want
//but the field already contains the changed value; so let's load the field instead of the $local.value-variable
//this is a bug within the ADITO-kernel
//TODO: change the workaround behaviour when $local.value is retrieved correct
organisationId = vars.getString("$field.ORGANISATION_ID");
var validationMsg = ContactUtils.validateOrganisationId(personId, organisationId, contactId);
if (validationMsg)
result.string(validationMsg);
\ No newline at end of file
var validationMsg = ContactUtils.validateIfAlreadyExists(personId, organisationId, contactId);
if (validationMsg)
result.string(validationMsg);
}
\ No newline at end of file
import("system.translate");
import("system.neon");
import("system.vars");
import("system.result");
......@@ -34,6 +35,44 @@ OrganisationUtils.getNameByOrganisationId = function(pOrganisationId)
*/
function ContactUtils() {}
/*
* validates if a ORGANISATION_ID in a person-contact is correct [=>does not already exist] or not [=>does already exist]
* this is done by checking the database for entires that do already exist with this combination of ORGANISATIONID and PERSONID
* gives different messages for private persons and contacts that do already exist
*
* @param {String} pPersonId the ID of the person that shall be searched in the database
* @param {String} pOrganisationId the ID of the organisation that shall be searched in the database;
* if this is an empty string it will be treated as private-dummy-organisation
* @param {String} [pOwnContactId] the CONTACTID of your current record; this is only needed when in EDIT-mode since you don't want to get a message
* for your own CONTACT;
* (if you do a lookup if a organisation-person-combination does already exist you'l get your own contact which you want to exclude)
*
* @return {String} translated text that describes whats the problem or null if there was no problem and everything is fine
*
*/
ContactUtils.validateIfAlreadyExists = function(pPersonId, pOrganisationId, pOwnContactId)
{
if (!pPersonId)
return null;
if (pOrganisationId == "")
pOrganisationId = "0";
var cond = SqlCondition.begin()
.andPrepare("CONTACT.PERSON_ID", pPersonId)
.andPrepare("CONTACT.ORGANISATION_ID", pOrganisationId)
//exclude the own since we do not want a "is not valid"-message for our own entry (on EDIT-mode)
.andPrepareIfSet("CONTACT.CONTACTID", pOwnContactId, "# != ?");
var sql = cond.buildSql("select CONTACT.CONTACTID from CONTACT");
var alreadyExistantContactId = db.cell(sql);
if (alreadyExistantContactId)
if (pOrganisationId.trim() == "0")
return translate.text("This private person doeas already exist and can not be created once more.");
else
return translate.text("This combination of person and organisation does already exist and can not be created once more.");
return null;
};
/**
* Get the type of contact. <br>
* In recordstate NEW or EDIT it loads the person- / orgid from the db.<br>
......
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