createRecord Documentation
Overview
The createRecord logic is designed to facilitate the creation of new records within the Vantage contacts application. This functionality allows users to either create a single record or multiple records simultaneously, utilizing both static field values and dynamic input data. The component is integral for applications that require seamless data entry and management within contact records.
Purpose
The primary purpose of the createRecord function is to create records in the contacts app by integrating with the application's data storage provider. It is particularly useful when bulk importing contact data or dynamically generating records based on user input or external data sources.
Settings
The createRecord function is configured through several critical settings, detailed as follows:
1. staticFields
- Input Type: Object
- Description: This setting allows users to define static field values that will be merged into each record created. These static fields can include fields like
firstName,lastName,email, etc. Changing the values in this object alters the default data included with every new record. - Default Value: An empty object (
{})
2. appType
- Input Type: String (derived from context or config)
- Description: Specifies the type of the app where the record is to be created. If not explicitly defined, it defaults to
contacts. Changing this setting allows the function to target different applications that may be integrated within Vantage. - Default Value: 'contacts' (if not provided through context or config)
How It Works
The createRecord function begins by determining the context it operates in, including the clientId and userId.
-
Error Handling: If the
clientIdis missing from the execution context, the function immediately returns an error response. -
Fetching Application Configuration: It retrieves the app's configuration based on the specified
clientIdandappType. -
Data Input Handling: It determines the input data, which can be provided directly or can default to the
staticFieldsif no other input is available. If multiple records are to be created, it supports an array of data. -
Record Creation: The function iteratively creates new records by merging
staticFieldswith each item from the input. Each created record is then collected in an array. -
Output: Upon successful record creation, the function returns the created records. If any error occurs during the process, it catches the error and formats it into a user-friendly message.
Data Expectations
The createRecord function expects the following data inputs:
- Input Data: An object or an array of objects representing the records to be created.
- If an array is provided, it allows for batch creation of multiple records.
- If an object is provided, it creates a singular record.
- Static Fields: An object defining additional values to be included in each record.
Integration with AI
While the current version of createRecord does not explicitly integrate with AI functionalities, it is designed such that it could be enhanced for future versions. For instance, fields created could leverage AI algorithms for data validation, sorting, or enriching data with additional contextual information from other sources.
Billing Impact
The createRecord functionality operates within the existing bounds of Vantage’s operational framework. Billing implications arise mainly from the volume of records created and the frequency of calls made to the service, particularly if there are thresholds for record creation in the user’s plan. Users should monitor their usage as excessive record creation may lead to additional charges depending on their subscription model.
Use Cases & Examples
Use Cases
-
Bulk Import of Contacts: A marketing team wants to upload a list of new leads to their contacts app for an upcoming campaign. They can provide an array of contact details and utilize the
createRecordfunction to import all at once. -
Creating Default Contact Records: A user wants to establish default values for new contacts. The marketing tool can set up static fields such as
sourceorcampaignID, ensuring that every newly created record contains this vital information without needing to input it individually. -
Integration with Third-Party Applications: A CRM system needs to synchronize new leads from a web form. When users submit their contact information online, the system can invoke
createRecordto instantly store these leads in the contacts application.
Detailed Example
Use Case: Bulk Import of Contacts
Configuration Example:
{
"inputs": {
"data": [
{ "firstName": "John", "lastName": "Doe", "email": "john.doe@example.com" },
{ "firstName": "Jane", "lastName": "Smith", "email": "jane.smith@example.com" }
]
},
"config": {
"staticFields": {
"source": "Web Form"
}
},
"context": {
"clientId": "12345",
"userId": "67890"
}
}Explanation:
In this configuration, two new contact records for John Doe and Jane Smith are created. Each record will automatically include the static field source with the value Web Form. This ensures that whenever these records are viewed later, teams can see the origin of these contacts.
In conclusion, createRecord serves as a powerful tool for efficiently managing contact records in Vantage, with extensive options for customization and operational flexibility.