Record Functions¶
Mythradon offers a versatile collection of record functions that are essential for managing data efficiently within the system. These functions are integrated into formula scripts, enabling users to create, manipulate, and retrieve records with precision and ease. Below is an overview of these functions:
- record\attribute() - Retrieves the value of a specified attribute from a record, essential for data extraction and conditions within scripts.
- record\count() - Counts the number of records that meet certain criteria, useful for data analysis and conditional operations.
- record\create() - Creates new records with predefined attributes, streamlining data entry and automation processes.
- record\exists() - Checks if a record exists based on given criteria, aiding in validation and decision-making processes.
- record\findOne() - Finds a single record that matches specified criteria, optimising for scenarios where only one result is needed or expected.
- record\findRelatedOne() - Retrieves a single related record, useful for accessing linked data within entity relationships.
- record\findRelatedMany() - Fetches multiple related records, facilitating operations on datasets involving related entities.
- record\relate() - Establishes a relationship between two records, critical for maintaining accurate linkages in relational data structures.
- record\relationColumn() - Retrieves the value of a specific column from a relationship table, allowing for refined data extraction from complex relational structures.
- record\unrelate() - Removes a relationship between two records, useful for data cleanup and reorganisation.
- record\update() - Updates attributes of an existing record, essential for maintaining current and accurate data.
- record\updateRelationColumn() - Modifies the value of a column in a relationship table, enabling dynamic changes to relational data.
These record functions provide comprehensive data management capabilities, supporting a wide range of data operations from simple queries to complex relational transactions. They are invaluable tools for developers and administrators in customising and extending the functionality of Mythradon.
record\attribute( )¶
The record\attribute() function retrieves the value of a specified attribute from a given record.
Examples:
$opportunityId = record\findOne('Opportunity', 'createdAt', 'desc', 'stage=', 'Closed Won');
$amountConverted = record\attribute('Opportunity', $opportunityId, 'amountConverted');
output\printLine($amountConverted);
$opportunityId = record\findOne('Opportunity', 'createdAt', 'desc', 'stage=', 'Closed Won');
$teamsIds = record\attribute('Opportunity', $opportunityId, 'teamsIds');
output\printLine($teamsIds);
By utilising this function along with record\findOne(), it's possible to fetch attribute values of any record in the system.
record\count( )¶
The record\count() function calculates the number of records that meet the specified criteria.
Returns a count of records with an optional primary FILTER applied.
Examples:
$accountName = 'Some Account Name';
$id = record\findOne('Account', 'createdAt', 'desc', 'name=', $accountName);
$count = record\count('Opportunity', 'accountId=', $id, 'stage=', 'Closed Won');
output\printLine($count);
FILTER is a name of a primary FILTER pre-defined in the system.
record\create( )¶
The record\create() function creates a new record of a specified ENTITY_TYPE, assigning attribute values based on provided key-value pairs. It returns the ID of the newly created record or NULL if the operation fails.
Examples:
This example will create a meeting record related to the current entity as identified by the entity\attribute() functions.
$id = record\create('Meeting',
'name', 'Sample Meeting',
'dateStart', datetime\today(),
'endStart', datetime\today(),
'status', 'Held',
'assignedUserId', entity\attribute('Id'),
'assignedUserName', entity\attribute('name')
);
The following example will create a new Account record and set the assigned user using the env\userAttribute() functions.
$AccountId = record\create('Account',
'name', 'Acme Inc',
'website', 'acmeinc.com',
'phoneNumber', '040666864',
'assignedUserId', env\userAttribute('id'),
'assignedUserName',env\userAttribute('name')
);
The following example will create an Account record and two Tasks and relate the tasks to the Account.
// Create Account record
$accountId = record\create('Account',
'name', 'Acme Inc 10',
'website', 'acmeinc.com',
'phoneNumber', '040666864',
'assignedUserId', env\userAttribute('id'),
'assignedUserName',env\userAttribute('name')
);
// Create Task 1
$taskId1 = record\create('Task',
'name', 'Sample Task 10.0',
'accountId', $accountId,
'dateStart', datetime\today(),
'endStart', datetime\today(),
'status', 'Held',
'assignedUserId', env\userAttribute('id'),
'assignedUserName',env\userAttribute('name')
);
// Create Task 2
$taskId2 = record\create('Task',
'name', 'Sample Task 10.1',
'accountId', $accountId,
'dateStart', datetime\today(),
'endStart', datetime\today(),
'status', 'Held',
'assignedUserId', env\userAttribute('id'),
'assignedUserName',env\userAttribute('name')
);
Note
To assign the record to User you will need to provide both the assignedUserId and assignedUserName fields.
record\exists( )¶
The record\exists() function verifies the existence of a record in a specified ENTITY_TYPE that matches given criteria, returning a boolean value to indicate whether the record exists.
Examples:
record\exists('Lead', 'emailAddress=', fromAddress);
record\exists('Lead', 'status=', list('Assigned', 'In Process'));
record\findOne( )¶
The record\findOne() function retrieves the ID of the first record within the specified ENTITY_TYPE that meets the defined criteria, sorted according to the ORDER_BY field and direction (ORDER). Optionally a FILTER can be used.
record\findOne(ENTITY_TYPE, ORDER_BY, ORDER, [KEY1, VALUE1, KEY2, VALUE2 ...]): STRING
Returns a first found ID of a record with an optional primary FILTER applied.
Examples:
record\findOne('Opportunity', 'createdAt', 'desc', 'accountId=', id, 'stage=', 'Closed Won');
FILTER is a name of a primary FILTER pre-defined in the system.
record\findRelatedOne( )¶
The record\findRelatedOne() function retrieves the ID of the first related record that matches specified criteria within a relationship. The function requires the base ENTITY_TYPE and its ID, along with the relationship LINK name. An ORDER_BY field and ORDER direction can be specified for sorting. Additional FILTER criteria can be applied to refine the search.
record\findRelatedOne(ENTITY_TYPE, ID, LINK, [ORDER_BY, ORDER, KEY1, VALUE1, KEY2, VALUE2 ...]): STRING
Returns a first found ID of a related record with an optional primary FILTER applied.
record\findRelatedOne(ENTITY_TYPE, ID, LINK, [ORDER_BY, ORDER, FILTER]): STRING
Note
If ORDER_BY and ORDER are omitted, a default sorting order is applied.
Examples:
record\findRelatedOne('Account', accountId, 'opportunities', 'createdAt', 'desc', 'stage=', 'Closed Won');
record\findRelatedOne('Account', accountId, 'opportunities', 'createdAt', 'desc', 'open');
FILTER is a name of a primary FILTER pre-defined in the system.
record\findRelatedMany( )¶
The record\findRelatedMany() function returns an array of IDs of a related record that matches specific criteria. LIMIT is the max number of record.
record\findRelatedMany(ENTITY_TYPE, ID, LINK, LIMIT, [ORDER_BY, ORDER, KEY1, VALUE1, KEY2, VALUE2 ...]): STRING[]
An alternate version of record\findRelatedMany() returns an array of IDs of a related record with an optional primary FILTER applied.
record\findRelatedMany(ENTITY_TYPE, ID, LINK, LIMIT, [ORDER_BY, ORDER, FILTER]): STRING[]
If NULL is passed for ORDER_BY and ORDER then a default order will be applied.
Examples:
record\findRelatedMany('Account', accountId, 'oppotunities', 10, 'createdAt', 'desc', 'stage=', 'Closed Won')
record\findRelatedOne('Account', accountId, 'oppotunities', 3, 'createdAt', 'desc', 'open')
FILTER is a name of a primary FILTER pre-defined in the system.
This function can be utilised for copying related records from one record to another. Example:
// copy teams from account to email
$ids = record\findRelatedMany('Account', $accountId, 'teams', 10);
record\relate('Email', $emailId, 'teams', $ids);
record\relate( )¶
The record\relate() function establishes relationships between records. In its basic form, the function links a single record to another record. Alternatively, a more advanced version of this function allows linking a record to multiple records specified by a list of IDs.
Examples:
LINK refers to the name of the link as defined in the Entity Manager Relationships.
Note
If a new record is being created, the formula cannot be processed in the Before save script because the record does not exist yet.
record\relationColumn( )¶
The `record\relationColumn() function returns a relationship column.
Example:
record\relationColumn('Account', $accountId, 'contacts', $contactId, 'role');
Example (condition checking position in team):
record\relationColumn('User', $someUserId, 'teams', 'some-team-id, 'role') == 'Support Manager'
record\unrelate( )¶
The record\unrelate() function unlinks two records.
Example:
Note
If a new record is being created, the formula cannot be processed in the Before save script because the record does not exist yet.
record\update( )¶
The record\update() function modifies an existing record by updating it with the provided attributes expressed as key-value pairs. It returns TRUE if the update is successful and FALSE if it fails.
Examples:
record\update('Meeting', 'SOME-MEETING-ID', 'emailAddress', 'SOME@ADDRESS.com', 'assignedUserId', 'SOME-USER-ID');
It will update the meeting with ID SOME-MEETING-ID, and will set emailAddress = 'SOME@ADDRESS.com', assignedUserId = 'SOME-USER-ID'.
record\updateRelationColumn( )¶
The record\updateRelationColumn() function updates a relationship column.
record\updateRelationColumn(ENTITY_TYPE, ID, LINK, FOREIGN_ID, COLUMN, VALUE): NULL
Example:
record\updateRelationColumn('Account', $accountId, 'contacts', $contactId, 'role', 'CEO');
See Also¶
- Array Functions
- Datetime Functions
- Entity Functions
- Env Functions
- Ext Functions
- JSON Functions
- Language Functions
- Number Functions
- Object Functions
- Output Functions
- Password Functions
- Record Functions
- String Functions
- Mythradon Marketing
- Mythradon Sales
- Mythradon Service
- Mythradon System Administration
- Mythradon Tools