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

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