Create contact without company

lock
push_pin
done
Besvaret
2

Hi

Is it possible to create contacts(Person) that has no associated company, through the api? I have set the global setting "Mandatory Company on Contact" to false.

The code below causes Object Reference exception somewhere in superOffice

    public async Task CreatePerson(int personId, string email, string firstName, string lastName)
    {
        var contactAgent = new ContactAgent(_config);
        try
        {
            var person = await contactAgent.AddPersonAsync(0, new PersonEntity()
            {
                Emails = new[] { new EntityElement() { Value = email } },
                Firstname = firstName,
                Lastname = lastName
            });
        }
        catch (Exception e)
        {
            throw;
        }
    }

26. sep. 2023 | 08.08 AM

Alle Svar (2)

Hi Snorre,

instead of creating a new PersonEntity object yourself and using contact.AddPerson, you should instead call personAgent.CreateDefaultPersonEntity, to get a valid object, and just modify it before saving it using personAgent.SavePersonEntity.

26. sep. 2023 | 09.23 AM
Thanks, that worked great.
26. sep. 2023 | 10.10 AM

Tilføj svar