Support > Administrator's guide (R7) > Running the script
ja | en

You can periodically run JavaScript running on the server side.

You can periodically run "scripts" prepared by developers.

Figure 1 Job settings
Before doing this setting,Prepare job execution accountplease.
  1. Log on with an account with administrator privileges.
  2. Open the "Job Management" "Job Schedule Search" screen from the menu.
  3. Click the "Register Screen" button to register a new job schedule.
  4. Select "ScriptCodeRunner" from the job name."Execute script" is displayed in the explanation column below that.
  5. In the job parameter, write the file name of the script you want to execute.Figure 1 specifies the file myjob.js.The extension is .js.
    myjob.js
  6. Specify scheduleTo do.
  7. Check the "valid" flag.
  8. Enter the account "jobadmin" to run this job.
  9. Register the job schedule.At the specified time, the script is executed.
The script here runs on the application server.

What is a script?

It is "server side JavaScript" provided by Java as standard.With Wagby, you can use this mechanism to develop business processing programs using JavaScript grammar.For details, refer to "Repository> Business logicPlease read.

Template of script file

The template of the script file is "repository> business logic> details of generated script file> Basic template"Please refer to.It becomes as follows.

function process() {
var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
var stdout = java.lang.System.out;

...ここに開発者独自のコードが埋め込まれる...

}

Please prepare a function named process in the script.This function is executed.

Saving the script file to

Save the created script file in the folder wagbyapp / webapps / wagby / WEB - INF / script / __ job.

In actual development, it is a good idea to prepare the script / __ job folder in customize / webapp / WEB-INF and save it here.Files existing in folders under customize are always reflected (overwritten) at build time.

Confirm operation

Save the following file as myjob.js in the wagbyapp / webapps / wagby / WEB-INF / script / __ job folder.(Initially, this __job folder does not exist, please create it manually.)

function process() {
var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
var stdout = java.lang.System.out;
stdout.println("Hello,JobScript");
}

After saving the above script, set up the ScriptCodeRunner job and "Run nowUse the button.Hello, JobScript is displayed on the Tomcat console running wagbyapp.

You can specify more than one parameter to specify for the job. The parameters that can be specified here are as follows.

Parameter name Required Description Description example
filename Specify the script file. myjob.js
maintenance You can switch to maintenance mode before running this job.Maintenance mode also ends after job execution. true
maintenanceOption Specify how to respond to the account that was logged on when switching to maintenance mode. Logout: Force logout of the account logged on before job execution.
Fail: If there is an account logged on before job execution, cause the job to fail.
(Default): Switch the mode while leaving the logged on account unchanged.
lock Specify the model to lock before executing.After the job is finished, the lock is canceled. Model name of customer etc. English.Multiple models can be specified with a space separator.
cache After the job is completed, the cache of the specified model is cleared. Model name of customer etc. English.Multiple models can be specified with a space separator.
Param: Parameter name 7.10 Specify the parameters to pass to the script.The character string following "param:" becomes the parameter name. param:targetdate

Receive parameters in script7.10

An example of specifying two parameters as shown in Fig. 2 is explained.

Keyvalue
param:targetdate2016-12-01
param:owneradmin
Figure 2 Specifying parameters

In the script file, you can use the parameter name directly as an internal variable.The type is a string.

function process() {
var ExcelFunction = Java.type("jp.jasminesoft.util.ExcelFunction");
var Jfcerror = Java.type("jp.jasminesoft.jfc.error.Jfcerror");
var Jfcwarn = Java.type("jp.jasminesoft.jfc.error.Jfcwarn");
var Jfcinfo = Java.type("jp.jasminesoft.jfc.error.Jfcinfo");
var stdout = java.lang.System.out;

stdout.println("targetdate="+targetdate);
stdout.println("owner="+owner);
}
  • The "value" passed to the parameter is a fixed value (character string).You can not specify a function here.For example, if you need today's date, try using new date () in your script to get today's date.Example: var d = new Date ();
  • The account that executed the script can be obtained with p.user.username.Example: stdout.println (p.user.username);

You can temporarily disable the job.

  1. Log on with an account with administrator privileges.
  2. Open the "Job" "Job Schedule Search" screen from the menu.
  3. Search the applicable "Job Schedule" and open the maintenance screen.
  4. Uncheck the "Enabled" flag and save it.
    Figure 3 Disabling Jobs

You can send the job execution result by e-mail.

Multiple job execution can not be performed.

If you make a job start every minute, if execution of this job is not completed in 1 minute, a new job will not be executed.

Instead of specifying time, you can also run this job now."Execute job immediatelyPlease read.