Class Customer
Represents a customer.
Syntax
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
Constructors
Customer()
Initializes a new instance of the Customer class.
Declaration
Customer
Examples
Customer c;
c.load(2); // Loads customer with id = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
Methods
addEmail(String,Integer,Integer)
Adds an email to a customer.
Declaration
Void addEmail(String email, Integer extTable, Integer dbiAgentId)
Parameters
| Type | Name | Description |
|---|---|---|
| String | Email address. |
|
| Integer | extTable | External owner of this email address as an extTable ID. extTable is a deprecated database integration called data sources. |
| Integer | dbiAgentId | External owner of this email address as a dbiAgent ID. |
Returns
| Type | Description |
|---|---|
| Void |
Remarks
Commonly used in database integrations.
Use addEmail(String,Integer,Integer,Integer) to provide the external sorting rank.Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
addEmail(String,Integer,Integer,Integer)
Adds an email to a customer with the external sorting rank.
Declaration
Void addEmail(String email, Integer externalRank, Integer extTable, Integer dbiAgentId)
Parameters
| Type | Name | Description |
|---|---|---|
| String | Email address |
|
| Integer | externalRank | External sorting rank. (Can't be changed in the Service GUI). |
| Integer | extTable | External owner of this email address as an extTable ID. extTable is a deprecated database integration called data sources. |
| Integer | dbiAgentId | External owner of this email address as a dbiAgent ID. |
Returns
| Type | Description |
|---|---|
| Void |
Remarks
Commonly used in database integrations.
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
checkFieldRights(String,String)
Checks if the current user has access to the field.
Declaration
Bool checkFieldRights(String field, String fieldRight)
Parameters
| Type | Name | Description |
|---|---|---|
| String | field | The field to check. |
| String | fieldRight | Type of access to check for - read or write. |
Returns
| Type | Description |
|---|---|
| Bool | True if the current user has access to the field; otherwise, false. |
Examples
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.
Declaration
Bool checkTableRights(String tableRight)
Parameters
| Type | Name | Description |
|---|---|---|
| String | tableRight | Type of access to check for - select, update, or insert. |
Returns
| Type | Description |
|---|---|
| Bool | True if the current user has access to the customer; otherwise, false. |
Examples
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.
Declaration
Bool findExternallyFromEmail(String email)
Parameters
| Type | Name | Description |
|---|---|---|
| String | The email address ("alias@domain"). |
Returns
| Type | Description |
|---|---|
| Bool | True if an entry is found; otherwise, false. |
Remarks
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.Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
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.
Declaration
Bool findExternallyFromEmail(String email, Integer extTable)
Parameters
| Type | Name | Description |
|---|---|---|
| String | The email address ("alias@domain"). |
|
| Integer | extTable | Used if you want to search only one data source. |
Returns
| Type | Description |
|---|---|
| Bool | True if an entry is found; otherwise, false. |
Remarks
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.
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
findExternallyFromKey(Integer,String)
Finds an external entry based on its primary key and table ID.
Declaration
Integer findExternallyFromKey(Integer table, String key)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | table | The external table (ext_table.id). |
| String | key | The primary key in the external table defining the entry. |
Returns
| Type | Description |
|---|---|
| Integer | True if found; otherwise, false. |
Remarks
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.Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
findFromAgentAndKey(Integer,String)
Finds a customer entry in the database based on the given agent ID and external key.
Declaration
Integer findFromAgentAndKey(Integer agent, String key)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | agent | The agent ID for the external entry. Implicitly defines the external data source. |
| String | key | The primary key of the external entry. |
Returns
| Type | Description |
|---|---|
| Integer | The ID for the customer entry in the database; or -1 if not found. |
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
findFromCellphone(String)
Finds an entry based on the cellphone.
Declaration
Bool findFromCellphone(String cellphone)
Parameters
| Type | Name | Description |
|---|---|---|
| String | cellphone | The cellphone to lookup. |
Returns
| Type | Description |
|---|---|
| Bool | True if found; otherwise, false. |
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
findFromEmail(String)
Find a Customer instance based on the email address.
Declaration
findFromEmail(String email)
Parameters
| Type | Name | Description |
|---|---|---|
| String | The address to look up. Must be address alone (alias@domain). |
Returns
| Type | Description |
|---|---|
| Bool | True if found; otherwise, false. |
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
getValue(String)
Returns the value of the given field of the customer.
Declaration
String getValue(String colName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | colName | The customer field to get data from. |
Returns
| Type | Description |
|---|---|
| String | The value of colName. |
Remarks
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").
Examples
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.
Declaration
Bool load(Integer id)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | id | The ID of the customer to load. |
Returns
| Type | Description |
|---|---|
| Bool | True if the customer exists; otherwise, false. |
Examples
Customer c;
print(c.load(3));
loadFromAgentAndKey(Integer,String)
Loads a customer based on agent id and external key.
Declaration
Bool loadFromAgentAndKey(Integer agent, String key)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | agent | The ID of the agent that owns this customer. |
| String | key | The external key of this customer. |
Returns
| Type | Description |
|---|---|
| Bool | True if operation was successful; false if the customer does not exist. |
Remarks
Loading might overwriting existing values.
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
login()
Creates a valid login session for the current customer.
Declaration
Void login()
Returns
| Type | Description |
|---|---|
| Void |
Remarks
Use getValue("loginSessionKey") to get the actual session key created.
Use logout() to kill the session.Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
logout()
Logs out a customer.
Declaration
Void logout()
Returns
| Type | Description |
|---|---|
| Void |
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
makeSalutation()
Creates a salutation greeting the customer.
Declaration
String makeSalutation()
Returns
| Type | Description |
|---|---|
| String | A salutation string. |
Remarks
Can be used in the beginning of a document or email.
Examples
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.
Declaration
Void removeEmail(String email)
Parameters
| Type | Name | Description |
|---|---|---|
| String | The email address you want to remove from the customer. |
Returns
| Type | Description |
|---|---|
| Void |
Remarks
For the action to take place, you must save().
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
removeExternalEmails(Integer,Integer)
Removes all external emails from a given source (extTable).
Declaration
Void removeExternalEmails(Integer p_0, Integer p_1)
Parameters
| Type | Name | Description |
|---|---|---|
| Integer | p_0 | |
| Integer | p_1 |
Returns
| Type | Description |
|---|---|
| Void |
Remarks
Used with set() to make sure emails deleted from the external source is deleted.
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
save()
Saves a customer. If ID is set, the customer will be updated. Otherwise, a new customer entry will be created.
Declaration
Integer save()
Returns
| Type | Description |
|---|---|
| Integer | The ID of the saved customer. |
Remarks
Use save(String) to provide the source key of the StoreAndProcess consent.
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
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.
Declaration
Integer save(String gdprSourceKey)
Parameters
| Type | Name | Description |
|---|---|---|
| String | gdprSourceKey | The source key of the StoreAndProcess consent to set (can be found in the consent system). |
Returns
| Type | Description |
|---|---|
| Integer | The ID of the saved customer. |
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();
setValue(String,String)
Sets the given field with the given value.
Declaration
Void setValue(String field, String value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | field | The field to set. |
| String | value | The value to set. |
Returns
| Type | Description |
|---|---|
| Void |
Remarks
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").
Examples
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.".
Declaration
Void toParser(Parser parser)
Parameters
| Type | Name | Description |
|---|---|---|
| Parser | parser | The parser to set. |
Returns
| Type | Description |
|---|---|
| Void |
Remarks
Consecutive calls will overwrite (rather than append) the values in the Parser instance.
Examples
Customer c;
c.load(2); // Loads customer with ID = 2
print(c.getValue("email")); // Returns a list of all emails
c.setValue("firstname", "Bob");
c.save();