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 totrue
.
Syntax
function findOrCreateExtendedField(extendedFieldInfo: ExtendedFieldInfo, [options: AuthOptions]): Promise<FoundOrCreatedExtendedField>
findOrCreateExtendedField Parameters
NAME
TYPE
DESCRIPTION
Custom field to find or create.
Authorization options.
Returns
Fulfilled - Extended field that was found or created.
Return Type:
NAME
TYPE
DESCRIPTION
Extended field that was found or created.
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?
1import { Permissions, webMethod } from 'wix-web-module';2import { contacts } from 'wix-crm-backend';34export const myFindOrCreateExtendedFieldFunction = webMethod(Permissions.Anyone, () => {5 const extendedFieldInfo = {6 displayName: "Last Contacted",7 dataType: "DATE"8 };9 const options = {10 suppressAuth: false11 };1213 return contacts.findOrCreateExtendedField(extendedFieldInfo, options)14 .then((extendedField) => {15 return extendedField;16 })17 .catch((error) => {18 console.error(error);19 });20});2122/*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": true36 * }37 */
1import { Permissions, webMethod } from 'wix-web-module';2import { contacts } from 'wix-crm-backend';34export const myFindOrCreateExtendedFieldFunction = webMethod(Permissions.Anyone, () => {5 const extendedFieldInfo = {6 displayName: "Last Contacted",7 dataType: "DATE"8 };9 const options = {10 suppressAuth: false11 };1213 return contacts.findOrCreateExtendedField(extendedFieldInfo, options)14 .then((extendedField) => {15 return extendedField;16 })17 .catch((error) => {18 console.error(error);19 });20});2122/*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": false36 * }37*/