> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a person with a new name, address, position using services

> How to update a person with a new name, address, position using NetServer services.

Let's discuss how we can update the name, address, and position of an existing person using NetServer services.

At the services layer, Person details can be updated only in one way: by using the `PersonAgent` and its `SavePersonEntity` method.

## Code

```csharp CS theme={null}
using SuperOffice;
using SuperOffice.CRM.Services;

using(SoSession newSession = SoSession.Authenticate("sam", "sam"))
{
  //Instantiating a Agents required
  using(PersonAgent newPerAgt = new PersonAgent())
  {
    using(ListAgent newLstAgt = new ListAgent())
    {
      //Retrieving a Person Entity
      PersonEntity newPerEnt = newPerAgt.GetPersonEntity(214);

      //Updating Properties of the Person Entity
      //String type properties
      newPerEnt.Firstname = "Luke";
      newPerEnt.Lastname = "Skywalker";

      //Updating a property of LocalizedField type
      LocalizedField[][] newAddress = newPerAgt.GetAddressByCountry(4, 144);
      newAddress[0][0].Value = "65, Sky Lane, LayLand.";
      newPerEnt.Address = newAddress;

      //Updating a Country type property
      newPerEnt.Country = newLstAgt.GetCountry(60);

      //Adding a EntityElement type Property
      //creating an Email
      EntityElement[] newEmailArr = new EntityElement[1];
      newEmailArr[0] = new EntityElement();
      newEmailArr[0].Value = "luke@example.com";
      newEmailArr[0].Description = "Testing";

      //Assigning the Email to the Email property of the Person
      newPerEnt.Emails = newEmailArr;

      //Modifying an existing Email
      newPerEnt.Emails[0].Value = "lukeUpdated@example.com";
      newPerEnt.Emails[0].Description = "Test Updated";

      //Assign the Position
      newPerEnt.Position = newLstAgt.GetPosition(1);

      //Saving the updated Person Entity
      newPerAgt.SavePersonEntity(newPerEnt);
    }
  }
}
```

## Walk-through

We need to use the `GetPersonEntity` method available in the `PersonAgent` to retrieve the `PersonEntity` that needs to be updated.

Once the Entity is retrieved, the properties that are exposed can be updated. The example shows how we can update different types of properties exposed by the `PersonEntity`.

Entity types consist of simple data types such as String, Boolean, DateTime, and int and complex data types consisting of types such as LocalizedFields and EntityElement types.

## Updating simple data types

Simple data types can be updated with basic statements as shown below.

```csharp CS theme={null}
      newPerEnt.Firstname = "Luke";
      newPerEnt.Lastname = "Skywalker";
```

## Updating complex data types

However, complex data types cannot be modified in such a way. For example, if we need to update the `Address` property of the `Person` we need to first create a localized field array and store the new address in the declared variable. Only once this is done can it be assigned to the Address property of the `PersonEntity`.

```csharp CS theme={null}
      LocalizedField[][] newAddress = newPerAgt.GetAddressByCountry(4, 144);
      newAddress[0][0].Value = "65, Sky Lane, LayLand.";
      newPerEnt.Address = newAddress;
```

Another example of a complex type is properties, which are of entity element types. In the above example, we have created an `EntityElement` array and assigned values to the properties of the declared variable.

```csharp CS theme={null}
      EntityElement[] newEmailArr = new EntityElement[1];
      newEmailArr[0] = new EntityElement();
      newEmailArr[0].Value = "luke@example.com";
      newEmailArr[0].Description = "Testing";
```

Once the assignment is done, the created email can be added to `Emails` property of the `PersonEntity` by executing the statement below.

```csharp CS theme={null}
using SuperOffice;
using SuperOffice.CRM.Services;

using(SoSession newSession = SoSession.Authenticate("sam", "sam"))
{
  //Instantiating a Agents required
  using(PersonAgent newPerAgt = new PersonAgent())
  {
    using(ListAgent newLstAgt = new ListAgent())
    {
      //Retrieving a Person Entity
      PersonEntity newPerEnt = newPerAgt.GetPersonEntity(214);

      //Updating Properties of the Person Entity
      //String type properties
      newPerEnt.Firstname = "Luke";
      newPerEnt.Lastname = "Skywalker";

      //Updating a property of LocalizedField type
      LocalizedField[][] newAddress = newPerAgt.GetAddressByCountry(4, 144);
      newAddress[0][0].Value = "65, Sky Lane, LayLand.";
      newPerEnt.Address = newAddress;

      //Updating a Country type property
      newPerEnt.Country = newLstAgt.GetCountry(60);

      //Adding a EntityElement type Property
      //creating an Email
      EntityElement[] newEmailArr = new EntityElement[1];
      newEmailArr[0] = new EntityElement();
      newEmailArr[0].Value = "luke@example.com";
      newEmailArr[0].Description = "Testing";

      //Assigning the Email to the Email property of the Person
      newPerEnt.Emails = newEmailArr;

      //Modifying an existing Email
      newPerEnt.Emails[0].Value = "lukeUpdated@example.com";
      newPerEnt.Emails[0].Description = "Test Updated";

      //Assign the Position
      newPerEnt.Position = newLstAgt.GetPosition(1);

      //Saving the updated Person Entity
      newPerAgt.SavePersonEntity(newPerEnt);
    }
  }
}
```

The above would appear as a new email in the emails list of the Person. However, if we are required to modify an already existing email the goal could be archived as follows.

```csharp CS theme={null}
      newPerEnt.Emails[0].Value = "lukeUpdated@example.com";
      newPerEnt.Emails[0].Description = "Test Updated";
```

Here we give the index of the Person's Email location that needs to be changed.

```csharp CS theme={null}
using SuperOffice;
using SuperOffice.CRM.Services;

using(SoSession newSession = SoSession.Authenticate("sam", "sam"))
{
  //Instantiating a Agents required
  using(PersonAgent newPerAgt = new PersonAgent())
  {
    using(ListAgent newLstAgt = new ListAgent())
    {
      //Retrieving a Person Entity
      PersonEntity newPerEnt = newPerAgt.GetPersonEntity(214);

      //Updating Properties of the Person Entity
      //String type properties
      newPerEnt.Firstname = "Luke";
      newPerEnt.Lastname = "Skywalker";

      //Updating a property of LocalizedField type
      LocalizedField[][] newAddress = newPerAgt.GetAddressByCountry(4, 144);
      newAddress[0][0].Value = "65, Sky Lane, LayLand.";
      newPerEnt.Address = newAddress;

      //Updating a Country type property
      newPerEnt.Country = newLstAgt.GetCountry(60);

      //Adding a EntityElement type Property
      //creating an Email
      EntityElement[] newEmailArr = new EntityElement[1];
      newEmailArr[0] = new EntityElement();
      newEmailArr[0].Value = "luke@example.com";
      newEmailArr[0].Description = "Testing";

      //Assigning the Email to the Email property of the Person
      newPerEnt.Emails = newEmailArr;

      //Modifying an existing Email
      newPerEnt.Emails[0].Value = "lukeUpdated@example.com";
      newPerEnt.Emails[0].Description = "Test Updated";

      //Assign the Position
      newPerEnt.Position = newLstAgt.GetPosition(1);

      //Saving the updated Person Entity
      newPerAgt.SavePersonEntity(newPerEnt);
    }
  }
}
```

With the execution of the above statement, a value will be assigned to the `Position` property of the Person.

<Note>
  `Position` property uses pre-defined SuperOffice values, which are different from the title.
</Note>

Once the required properties of the `PersonEntity` have been modified the modifications could be saved to the database with the execution of the below statement.

```csharp CS theme={null}
using SuperOffice;
using SuperOffice.CRM.Services;

using(SoSession newSession = SoSession.Authenticate("sam", "sam"))
{
  //Instantiating a Agents required
  using(PersonAgent newPerAgt = new PersonAgent())
  {
    using(ListAgent newLstAgt = new ListAgent())
    {
      //Retrieving a Person Entity
      PersonEntity newPerEnt = newPerAgt.GetPersonEntity(214);

      //Updating Properties of the Person Entity
      //String type properties
      newPerEnt.Firstname = "Luke";
      newPerEnt.Lastname = "Skywalker";

      //Updating a property of LocalizedField type
      LocalizedField[][] newAddress = newPerAgt.GetAddressByCountry(4, 144);
      newAddress[0][0].Value = "65, Sky Lane, LayLand.";
      newPerEnt.Address = newAddress;

      //Updating a Country type property
      newPerEnt.Country = newLstAgt.GetCountry(60);

      //Adding a EntityElement type Property
      //creating an Email
      EntityElement[] newEmailArr = new EntityElement[1];
      newEmailArr[0] = new EntityElement();
      newEmailArr[0].Value = "luke@example.com";
      newEmailArr[0].Description = "Testing";

      //Assigning the Email to the Email property of the Person
      newPerEnt.Emails = newEmailArr;

      //Modifying an existing Email
      newPerEnt.Emails[0].Value = "lukeUpdated@example.com";
      newPerEnt.Emails[0].Description = "Test Updated";

      //Assign the Position
      newPerEnt.Position = newLstAgt.GetPosition(1);

      //Saving the updated Person Entity
      newPerAgt.SavePersonEntity(newPerEnt);
    }
  }
}
```


## Related topics

- [Update a SuperOffice CRM Contact action](/integrations/zapier/howto/actions/update-contact.md)
- [Person table](/en/api/bulk-operations/bulk-update/reference/person-table.md)
- [Create a new contact](/en/contact/learn/create.md)
- [Create a new company](/en/api/web-services/howto/company/create-contact.md)
- [Using targets in tiles](/en/dashboard/learn/show-sales-targets.md)
- [Create a SuperOffice CRM Contact action](/integrations/zapier/howto/actions/create-contact.md)
