Search.../

findOrCreateExtendedField( )

Retrieves a custom field with a given name, or creates one if it doesn't exist.

Description

The findOrCreateExtendedField() function returns a Promise that resolves when the specified custom field is found or created.

Successful calls to findOrCreateExtendedField() always return an extended field, which can be passed to subsequent function calls.

To find an existing extended field without potentially creating a new one, use getExtendedField() or queryExtendedFields().

Note: Only visitors with Manage Contacts permissions can find or create extended fields. You can override the permissions by setting the suppressAuth option to true.

Syntax

function findOrCreateExtendedField(extendedFieldInfo: ExtendedFieldInfo, [options: AuthOptions]): Promise<FoundOrCreatedExtendedField>

findOrCreateExtendedField Parameters

NAME
TYPE
DESCRIPTION
extendedFieldInfo
ExtendedFieldInfo

Custom field to find or create.

options
Optional
AuthOptions

Authorization options.

Returns

Fulfilled - Extended field that was found or created.

Return Type:

Promise<FoundOrCreatedExtendedField>
NAME
TYPE
DESCRIPTION
extendedField
ExtendedField

Extended field that was found or created.

newExtendedField
boolean

Indicates whether the extended field was just created or already existed.

If the field was just created, returns true. If it already existed, returns false.

Was this helpful?

Create an extended field

Copy Code
1import { contacts } from 'wix-crm-backend';
2
3export function myFindOrCreateExtendedFieldFunction() {
4 const extendedFieldInfo = {
5 displayName: "Last Contacted",
6 dataType: "DATE"
7 };
8 const options = {
9 suppressAuth: false
10 };
11
12 return contacts.findOrCreateExtendedField(extendedFieldInfo, options)
13 .then((extendedField) => {
14 return extendedField;
15 })
16 .catch((error) => {
17 console.error(error);
18 });
19}
20
21/*
22 * Promise that resolves to:
23 *
24 * {
25 * "extendedField": {
26 * "_createdDate": "2021-01-19T23:18:16.550Z",
27 * "_updatedDate": "2021-01-19T23:18:16.550Z"
28 * "namespace": "custom",
29 * "key": "custom.last-contacted",
30 * "displayName": "Last Contacted",
31 * "dataType": "DATE",
32 * "fieldType": "USER_DEFINED",
33 * },
34 * "newExtendedField": true
35 * }
36 */
Find an extended field

Copy Code
1import { contacts } from 'wix-crm-backend';
2
3export function myFindOrCreateExtendedFieldFunction() {
4 const extendedFieldInfo = {
5 displayName: "Last Contacted",
6 dataType: "DATE"
7 };
8 const options = {
9 suppressAuth: false
10 };
11
12 return contacts.findOrCreateExtendedField(extendedFieldInfo, options)
13 .then((extendedField) => {
14 return extendedField;
15 })
16 .catch((error) => {
17 console.error(error);
18 });
19}
20
21/*
22 * Promise resolves to:
23 *
24 * {
25 * "extendedField": {
26 * "_createdDate": "2021-01-19T23:18:17Z",
27 * "_updatedDate": "2021-01-19T23:18:17Z"
28 * "namespace": "custom",
29 * "key": "custom.last-contacted",
30 * "displayName": "Last Contacted",
31 * "dataType": "DATE",
32 * "fieldType": "USER_DEFINED",
33 * },
34 * "newExtendedField": false
35 * }
36*/