English
npcRun
About 296 wordsLess than 1 minute
2025-09-22
Executes hook logic with the latest context. This is similar to how various hooks are triggered by default at the underlying level, and is suitable for implementing logic that needs to run outside the plugin lifecycle, such as button click events.
Parameters
| Parameter | Description | Type |
|---|---|---|
| hook | Required, a hook function or hook event name | Function|String |
| params | Custom hook event parameters, passed to event receivers | Object |
| opt | Optional configuration parameter | Number |
Return Value
None
Code Example
[{
event: "form.render.before",
functional: function (pluginExecResult, options) {
let {bizApi}=options;
// Find the button whose apiName is custom_btn_test1__c
let btn1 = options.buttons.find(it=>it.api_name==="custom_btn_test1__c");
if(btn1){
// Example 1: call inside the button click function defined in a plugin hook,
// directly execute the hook function to update data and UI state
btn1.onClick = function(){
bizApi.npcRun(p=>{
let newDataIndexs = p.dataUpdater.add([{...}]);// Use the re-obtained dataUpdater in parameters to add detail data
return p.bizApi.triggerCalAndUIEvent({
objApiName: 'SaleOrderProductObj',// Object that initiates the calculation, required
newDataIndexs, // dataIndex list of newly added detail data, required if the calculation is triggered because detail data was added
})
})
}
}
// Find the button whose apiName is custom_btn_test2__c
let btn2 = options.buttons.find(it=>it.api_name==="custom_btn_test2__c");
if(btn2){
// Example 2: call inside the button click function defined in a plugin hook,
// emit a custom plugin hook event, which can be received and handled through generic plugin event registration
btn2.onClick = function(){
bizApi.npcRun("plugin1.btn.onClick", {test:"Custom event parameters"})
.then(rst=>{
// Get the event handling result
})
}
}
}
},
{
event: "plugin1.btn.onClick",
functional: function (pluginExecResult, options) {
// Handle the custom plugin event
let {test} = options;
console.log(test);// Custom event parameters
}
}]Notes
- Executes the hook with a new plugin context, so do not call it within the lifecycle of another plugin hook.
