Skip to content

I want to be able to set multiple $p.events.on_editor_load

Answer

This can be achieved in one of the following ways.
1. Add the process you want to execute to an array, and call the processes stored in the array in sequence with $p.events.on_editor_load.
1. Define the process you want to execute as a single function, and call the function in sequence with $p.events.on_editor_load.


Overview

If you write $p.events.on_editor_load multiple times across multiple script files, the scripts will be overwritten and only the most recent one will work. There are two ways to work around this:
1. Add the process you want to execute to an array, and call the processes stored in the array in sequence with $p.events.on_editor_load.
1. Define the process you want to execute as a single function, and call the function in sequence with $p.events.on_editor_load.

In addition to $p.events.on_editor_load, the same problem occurs with $p.events.on_grid_load and other "Event Firing Script," and can be avoided with this content.

1. Add the process you want to execute to an array, and call the processes stored in the array in sequence with $p.events.on_editor_load

Sample Code

JavaScript
//Define an array
$p.events.on_editor_load_arr = [];
JavaScript
//Add process 1
$p.events.on_editor_load_arr.push(function() {
    alert("test1"); //Any process
});
JavaScript
//Add process 2
$p.events.on_editor_load_arr.push(function() {
    alert("test2"); //Any process
});
JavaScript
//Execution
$p.events.on_editor_load = function() {
    for (let i = 0; i < $p.events.on_editor_load_arr.length; i++) {
        $p.events.on_editor_load_arr[i] ();
    }
}

Register the following in Pleasanter's "Script".
Script list with entries registered from ID=1 through ID=4
Register the "Define an array" script at ID=1, and the "Execution" script at ID=4. Register the scripts to add the processes you want to execute at ID=2 and ID=3. In this example, two processes are added, but you can add any number of processes by writing them between ID=1 and ID=4.

2. Define the process you want to execute as one function, and call the functions sequentially with $p.events.on_editor_load

Sample

JavaScript
//Define process 1
$p.ex.myFunc1 = function() {
    alert("test1"); //Any process
}
JavaScript
//Define process 2
$p.ex.myFunc2 = function() {
    alert("test2"); //Any process
}
JavaScript
//Execute
$p.events.on_editor_load = function() {
    $p.ex.myFunc1();
    $p.ex.myFunc2();
}

Register the following in the "Script" of Pleasanter.
Script list with entries registered from ID=1 through ID=3
Register the script for the function defined with ID=1,2. Register the "Execution" script with ID=3. In this example, two processes are added, but you can add as many processes as you want by listing them before ID=3.