Remove company when saving a person

lock
push_pin
done
Answered
2

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?

1 Oct 2024 | 03:08 PM

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

2 Oct 2024 | 07:11 AM
Hi Eivind,
Thank you - luckily this is a small customer, and the extra load needed to initialize the NS classes, will probably not be a problem. The extra wait time is almost not noticeable and the user UI experience is the same: Data is as expected when person is saved (without the need of reload).

But since you also expected the eventdata solution to work, to me it seems like a bug.
7 Oct 2024 | 01:31 PM

Add reply