Remove company when saving a person
I have a customer where persones in SuperOffice 9 out of 10 times is not connected to a company.
Hence the customer want company to be automatically removed when creating a person.
I expected to be able to use a "Before saving contact" trigger, and set PersonEntity.Contact.ContactId = 0
But person is still added to a company (active company).
This is the unsuccesfull code:
#setLanguageLevel 4;
EventData ed = getEventData();
// remove company on person
ed.setOutputValue("PersonEntity.Contact.ContactId","0"); // <== does not work :(
I have also tried these properties:
ed.setOutputValue("ActiveContactId","0");
ed.setOutputValue("ContactId","0");
Does anyone have an idea how to remove company on person when a person is created?
All Replies (2)
Hello Morten,
I will have to look into this, but it should in theory be possible to do what you are doing..
A workaround, while you wait for me to get back to you, would be to use the AfterSaveContact instead, and load/edit the personEntity there:
#setLanguageLevel 4;
EventData ed = getEventData();
if(ed.getInputValue("IsNew").toBool()){
NSPersonAgent pAgent;
NSPersonEntity pEntity = pAgent.GetPersonEntity(ed.getInputValue("PersonEntity.PersonId").toInteger());
NSContact contact;
contact.SetContactId(0);
pEntity.SetContact(contact);
pAgent.SavePersonEntity(pEntity);
}
I will update the thread when i figure out if this is a bug or if I've missed something.
//Eivind