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

# Customer

> Represents a customer.

Represents a customer.

## Constructors

### Customer()

```crmscript theme={null}
Customer
```

Initializes a new instance of the Customer class.

## Methods

## addEmail(String,Integer,Integer)

Adds an email to a customer.

```crmscript theme={null}
Void addEmail(String email, Integer extTable, Integer dbiAgentId)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Commonly used in database integrations.

  Use addEmail(String,Integer,Integer,Integer) to provide the external sorting rank.
</Note>

## addEmail(String,Integer,Integer,Integer)

Adds an email to a customer with the external sorting rank.

```crmscript theme={null}
Void addEmail(String email, Integer externalRank, Integer extTable, Integer dbiAgentId)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Commonly used in database integrations.
</Note>

## checkFieldRights(String,String)

Checks if the current user has access to the field.

```crmscript theme={null}
Bool checkFieldRights(String field, String fieldRight)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if the current user has access to the field; otherwise, false.

**Example:**

```crmscript theme={null}
Customer c;
c.load(3);
Bool b = c.checkFieldRights("person","read");
print(b.toString());
```

## checkTableRights(String)

Use this function to see if the current user has access to this customer.

```crmscript theme={null}
Bool checkTableRights(String tableRight)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if the current user has access to the customer; otherwise, false.

**Example:**

```crmscript theme={null}
Customer c;
c.load(3);
Bool b = c.checkTableRights("select");
print(b.toString());
```

## findExternallyFromEmail(String)

Finds an entry in the external database based on an email address.

```crmscript theme={null}
Bool findExternallyFromEmail(String email)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if an entry is found; otherwise, false.

<Note>
  It will search all external data sources for a Customer matching the given email address. If an entry is found, a proxy entry is created and saved.

  Use findExternallyFromEmail(String,Integer) to provide an extTable ID to limit the search to 1 data source.
</Note>

## findExternallyFromEmail(String,Integer)

Finds an entry in the external database based on an email address and an extTable ID to limit the search to one data source.

```crmscript theme={null}
Bool findExternallyFromEmail(String email, Integer extTable)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if an entry is found; otherwise, false.

<Note>
  It will search all external data sources for a Customer matching the given email address. If an entry is found, a proxy entry is created and saved.
</Note>

## findExternallyFromKey(Integer,String)

Finds an external entry based on its primary key and table ID.

```crmscript theme={null}
Integer findExternallyFromKey(Integer table, String key)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - True if found; otherwise, false.

<Note>
  Searches for and possibly creates a proxy entry for an external entry based on the external table (implicitly defines data source), and the primary key.

  If an proxy entry already exists, it is loaded. If not, the given external data source is searched, and if an entry is found, a local proxy entry is created and saved.
</Note>

## findFromAgentAndKey(Integer,String)

Finds a customer entry in the database based on the given agent ID and external key.

```crmscript theme={null}
Integer findFromAgentAndKey(Integer agent, String key)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The ID for the customer entry in the database; or -1 if not found.

## findFromCellphone(String)

Finds an entry based on the cellphone.

```crmscript theme={null}
Bool findFromCellphone(String cellphone)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if found; otherwise, false.

## findFromEmail(String)

Find a Customer instance based on the email address.

```crmscript theme={null}
findFromEmail(String email)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if found; otherwise, false.

## getValue(String)

Returns the value of the given field of the customer.

```crmscript theme={null}
String getValue(String colName)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The value of colName.

<Note>
  Available fields:

  * id
  * name The name of the customer.
  * firstname
  * lastname
  * phone
  * cellphone
  * note
  * username: This is the username used for the external web.
  * password: This field is deprecated from v10.2.5. Empty string will be returned. Use authenticateCustomer() instead.
  * email: A list of all email addresses.
  * mainEmail: The main email address.
  * language: The name, languagecode or ID of the customers language.
  * deleted
  * company: The ID of the related company
  * display\_company: The value showing the name of the related company.
  * dbi\_agent\_id
  * dbi\_key
  * dbi\_last\_modified
  * dbi\_last\_syncronized These values are for database integration
  * priority: The id or name of the customers priority.
  * our\_contact: The username, loginname or ID of the related contact (user).
  * x\_\*: The extrafield with the given database field name.\[extra field] The extrafield with the given name (for example, "Country").
</Note>

**Example:**

```crmscript theme={null}
Customer c;
c.load(3);
Bool b = c.checkTableRights("select");
print(b.toString());
c.setValue("name", "Test");
print(c.getValue("name"));
```

## load(Integer)

Loads the customer with the given ID.

```crmscript theme={null}
Bool load(Integer id)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if the customer exists; otherwise, false.

**Example:**

```crmscript theme={null}
Customer c;
print(c.load(3));
```

## loadFromAgentAndKey(Integer,String)

Loads a customer based on agent id and external key.

```crmscript theme={null}
Bool loadFromAgentAndKey(Integer agent, String key)
```

**Returns:** [CRMScript.Global.Bool](CRMScript.Global.Bool) - True if operation was successful; false if the customer does not exist.

<Note>
  Loading might overwriting existing values.
</Note>

## login()

Creates a valid login session for the current customer.

```crmscript theme={null}
Void login()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Use getValue("loginSessionKey") to get the actual session key created.

  Use logout() to kill the session.
</Note>

## logout()

Logs out a customer.

```crmscript theme={null}
Void logout()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## makeSalutation()

Creates a salutation greeting the customer.

```crmscript theme={null}
String makeSalutation()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - A salutation string.

<Note>
  Can be used in the beginning of a document or email.
</Note>

**Example:**

```crmscript theme={null}
Customer c;
c.load(3);
Bool b = c.checkTableRights("select");
print(b.toString());
c.setValue("name", "Test");
c.setValue("salutation", "Welcome to SuperOffice");
c.makeSalutation();
```

## removeEmail(String)

Removes the email address from the customer.

```crmscript theme={null}
Void removeEmail(String email)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  For the action to take place, you must save().
</Note>

## removeExternalEmails(Integer,Integer)

Removes all external emails from a given source (extTable).

```crmscript theme={null}
Void removeExternalEmails(Integer p_0, Integer p_1)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Used with set() to make sure emails deleted from the external source is deleted.
</Note>

## save()

Saves a customer. If ID is set, the customer will be updated. Otherwise, a new customer entry will be created.

```crmscript theme={null}
Integer save()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The ID of the saved customer.

<Note>
  Use save(String) to provide the source key of the StoreAndProcess consent.
</Note>

## save(String)

Saves a customer with the source key of the StoreAndProcess consent. If ID is set, the customer will be updated. Otherwise, a new customer entry will be created.

```crmscript theme={null}
Integer save(String gdprSourceKey)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The ID of the saved customer.

## setValue(String,String)

Sets the given field with the given value.

```crmscript theme={null}
Void setValue(String field, String value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Available fields:

  * name or display\_name: The name of the customer.
  * firstname
  * lastname
  * title (From 7.x)
  * mrmrs (From 7.x)
  * year\_of\_birth (From 7.x)
  * month\_of\_birth (From 7.x)
  * day\_of\_birth (From 7.x)
  * birth\_date (From 7.x)
  * person\_number (From 7.x)
  * post1 (From 7.x)
  * post2 (From 7.x)
  * post3 (From 7.x)
  * salutation (From 7.x)
  * middleName (From 7.x)
  * phone
  * direct/formattedNumber: Same as phone(From 7.x)
  * phone/formattedNumber: Same as phone (From 7.x)
  * cellphone
  * mobile/formattedNumber: Same as cellphone (From 7.x)
  * note
  * infoText: Same as note. (From 7.x)
  * username: This is the usedname used for the external web.
  * password: This is the password used for the external web.
  * email or display\_email: Adds an email to the customer (does not erase existing ones).
  * company: The ID of the related company
  * display\_company: The value showing the name of the related company.
  * deleted
  * dbi\_agent\_id
  * dbi\_key
  * dbi\_last\_modified
  * dbi\_last\_syncronized: These values are for database integration
  * priority or priority\_id: The id or name of the customers priority.
  * language: The name, languagecode or ID of the customers language.
  * ourContact: The username, loginname or ID of the related contact (user).
  * x\_\* The extrafield with the given database field name.
  * \[extra field] The extrafield with the given name (for example, "Country").
</Note>

**Example:**

```crmscript theme={null}
Customer c;
c.load(3);
Bool b = c.checkTableRights("select");
print(b.toString());
c.setValue("name", "Test");
print(c.getValue("name"));
```

## toParser(Parser)

Fills a Parser object with a Customer's values, including extra fields. The fields are prefixed with "customer.".

```crmscript theme={null}
Void toParser(Parser parser)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Consecutive calls will overwrite (rather than append) the values in the Parser instance.
</Note>


## Related topics

- [Customer center](/en/customer-center/learn/index.md)
- [Customer Centre](/en/customer-center/overview.md)
- [Customer languages](/en/localization/learn/customer-languages.md)
- [Reply to customer](/en/automation/crmscript/howto/request/reply.md)
- [Add customer language](/en/localization/admin/add-customer-language.md)
- [Configure Customer Centre](/en/customer-center/learn/config.md)
