Create custom fields for a customer

Create the custom field

To create a custom field for a customer, use the Fluent API and perform the following:

  1. Get the Type of the Customer.
  2. Create a new custom field.
  3. Save the changes.

Use the following code sample:

Set the value of the custom field

To set the value of the field perform the following:

  1. Get the orders manager.
    Get an instance of the OrdersManager object.
  2. Get the customer.
    Get an instance of the specified customer. For more information, see For developers: Query customers.
  3. Get the custom fields for the customer.
    To get the available custom fields for the customer, call the GetProperties static method of the TypeDescriptor class and pass the instance of the customer as an argument.
  4. Get the custom field.
    Get the PropertyDescriptor instance for the specified custom field.
  5. Check whether the field exists.
    If the field exists you can set it. Otherwise, skip the next steps.
  6. Set the value of the custom field.
    To set the value of the custom field, call the SetValue extension method of the Customer instance. Pass the name of the field and its value.

    NOTE: To use the SetValue method you must add an using clause for the Telerik.Sitefinity.Model namespace.

  7. Save the changes.
    Save the changes to the manager.

Use the following code sample:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?