> ## 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.

# How to display all user-defined fields

> How to display all user-defined fields using services.

This example shows how to get all the user-defined fields along with the field values on a given contact.

<Note>
  The code examples on this page use the nuget SOAP proxies, [SuperOffice.NetServer.Services][1].
</Note>

![How to display all user-defined fields -screenshot][img1]

## Code

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

try
{
  using (SoSession newSession = SoSession.Authenticate("sal0", ""))
  {
    Console.Write("Please enter the contact ID: ");

    // Read the contact id
    String contactId = Console.ReadLine();
    Console.WriteLine("");

    // Check if a contact id entered
    if (!(String.IsNullOrEmpty(contactId.Trim())))
    {
      // Create a Contact Agent
      ContactAgent agent = new ContactAgent();

      // Get a Contact Entity through the Contact Agent
      ContactEntity contactEntity = agent.GetContactEntity(int.Parse(contactId.Trim()));

      // Create a UserDefinedFieldInfoAgent
      UserDefinedFieldInfoAgent udefFieldInfoAgent = new UserDefinedFieldInfoAgent();

      // Get the User defined field list on 'Contact'
      UserDefinedFieldInfo[] udefFieldInfo= udefFieldInfoAgent.GetUserDefinedFieldList(7);

      // Print the contact member details
      Console.WriteLine("User defined field list for the contact " + contactEntity.Name);
      Console.WriteLine("");
      foreach (UserDefinedFieldInfo field in udefFieldInfo)
      {
        string labelName = field.FieldLabel;
        string fieldValue = contactEntity.UserDefinedFields[field.ProgId];
        Console.WriteLine("Field Name = " + labelName + "    Value = " + fieldValue);
      }
      Console.ReadKey();
    }
    else
    {
      Console.WriteLine("Please enter the contact id.");
      Console.ReadKey();
    }
  }
}
catch (Exception ss)
{
  Console.WriteLine(ss.Message);
  Console.ReadKey();
}
```

## Walk-through

In the above example, we have used the `GetUserDefinedFieldList` method of `SuperOffice.CRM.Services.IUserDefinedFieldInfoAgent` to get the user-defined field list. This method returns information about all the user-defined fields on a particular owner type (such as project, contact, and person). We have specified Contact as the type, as shown below:

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

try
{
  using (SoSession newSession = SoSession.Authenticate("sal0", ""))
  {
    Console.Write("Please enter the contact ID: ");

    // Read the contact id
    String contactId = Console.ReadLine();
    Console.WriteLine("");

    // Check if a contact id entered
    if (!(String.IsNullOrEmpty(contactId.Trim())))
    {
      // Create a Contact Agent
      ContactAgent agent = new ContactAgent();

      // Get a Contact Entity through the Contact Agent
      ContactEntity contactEntity = agent.GetContactEntity(int.Parse(contactId.Trim()));

      // Create a UserDefinedFieldInfoAgent
      UserDefinedFieldInfoAgent udefFieldInfoAgent = new UserDefinedFieldInfoAgent();

      // Get the User defined field list on 'Contact'
      UserDefinedFieldInfo[] udefFieldInfo= udefFieldInfoAgent.GetUserDefinedFieldList(7);

      // Print the contact member details
      Console.WriteLine("User defined field list for the contact " + contactEntity.Name);
      Console.WriteLine("");
      foreach (UserDefinedFieldInfo field in udefFieldInfo)
      {
        string labelName = field.FieldLabel;
        string fieldValue = contactEntity.UserDefinedFields[field.ProgId];
        Console.WriteLine("Field Name = " + labelName + "    Value = " + fieldValue);
      }
      Console.ReadKey();
    }
    else
    {
      Console.WriteLine("Please enter the contact id.");
      Console.ReadKey();
    }
  }
}
catch (Exception ss)
{
  Console.WriteLine(ss.Message);
  Console.ReadKey();
}
```

Then we loop through the `UserDefinedFieldInfo` collection to get the field label and the corresponding value for each user-defined field.  The contact entity has a string dictionary of user-defined data. The `ProgId` of the user-defined field is passed to the udef field data dictionary to get the corresponding field value:

```csharp CS theme={null}
      foreach (UserDefinedFieldInfo field in udefFieldInfo)
      {
        string labelName = field.FieldLabel;
        string fieldValue = contactEntity.UserDefinedFields[field.ProgId];
        Console.WriteLine("Field Name = " + labelName + "    Value = " + fieldValue);
      }
```

<a href="../../../../../downloads/api/getalluserdefinedfieldsonacontact.zip" download>Click to download source code (zip)</a>

[1]: https://www.nuget.org/packages/SuperOffice.NetServer.Services

[img1]: /media/loc/en/api/web-services/image002-6.jpg


## Related topics

- [How to get all user-defined fields using the web services API](/en/api/web-services/howto/custom-objects/rest-get-all-udef-fields.md)
- [How to set a user-defined list item on a Udef field (services)](/en/api/web-services/howto/custom-objects/set-udef-listitem-value.md)
- [How to update a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-update-udef-field.md)
- [How to create a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-create-udef-field.md)
- [How to delete a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-delete-udef-field.md)
- [Customize layout of user-defined fields](/en/custom-objects/admin/edit-udef-layout.md)
