English
md.add.before
About 247 wordsLess than 1 minute
2025-12-15
This hook is triggered before adding child-object data. It allows extra business actions before adding child-object data, including but not limited to intercepting the add operation.
- Intercept adding child-object data
Parameters
| Parameter | Description | Type |
|---|---|---|
| Common parameters | See details | -- |
| objApiName | Child object apiName | String |
| recordType | Child object record type | String |
| newData | Newly added child-object data | Object |
| newDataIndexs | Row IDs of the newly added child-object data | Array |
Basic Example
Intercept adding child-object data
export default class Plugin {
apply() {
return [{
event: 'md.add.before',
functional: this.mdAddBefore.bind(this)
}]
}
// If this is a middleware plugin in a vcrm project, swap the interaction parameter positions
// mdAddBefore(plugin, context)
mdAddBefore(context, plugin) {
return new Promise((resolve, reject) => {
let {newData} = context;
// If you want to modify some field values of the data being added, directly modify newData
// newData.sex = 'xxx'
if(newData.name === 'xxx') {
reject();// intercept and prevent adding
} else {
resolve();// allow normal adding
}
})
}
}Notes
1. Field values changed in this hook will also participate in subsequent calculations/UI events
After data is modified in this hook, subsequent calculations and UI events will be processed based on the updated field values.
2. In this hook, child-object data obtained through context APIs does not include the newly added data
When this hook is called, the object data has not been fully created yet, so the API cannot find the new data in the object data.
