Call a Script From a Configuration File

To call a script from a configuration file, provide the script source or reference a file that contains the script source. For example:

{
    "type" : "text/javascript",
    "source": string
} 

or

{
   "type" : "text/javascript",
   "file" : file location
} 

Script variables are not necessarily simple key:value pairs, and can be any arbitrarily complex JSON object.

type

string, required

Specifies the type of script to be executed. Supported types include text/javascript and groovy.

source

string, required if file is not specified

Specifies the source code of the script to be executed.

file

string, required if source is not specified

Specifies the file containing the source code of the script to execute. The file path must be relative to project-dir. Absolute paths are not supported.

Tip

In general, you should namespace variables passed into scripts with the globals map. Passing variables in this way prevents collisions with the top-level reserved words for script maps, such as file, source, and type. The following example uses the globals map to namespace the variables passed in the previous example.

"script": {
    "type" : "text/javascript",
    "file" : "script/triggerEmailNotification.js",
    "globals" : {
        "fromSender" : "admin@example.com",
        "toEmail" : "user@example.com"
    }
}

The following example script (included in sync.json) determines whether to include or ignore a target object in the reconciliation process based on an employeeType of true:

"validTarget" : {
    "type" : "text/javascript",
    "source" : "target.employeeType == 'external'"
}

The following example script (included in sync.json) sets the __PASSWORD__ attribute to defaultpwd when IDM creates a target object:

"onCreate" : {
    "type" : "text/javascript",
    "source" : "target.__PASSWORD__ = 'defaultpwd'"
}

The following example script (included in router.json) uses a trigger to create Solaris home directories using a script. The script is located in the file, project-dir/script/createUnixHomeDir.js :

{
    "filters" : [
        {
            "pattern" : "^system/solaris/account$",
            "methods" : [ "create" ],
            "onResponse" : {
                "type" : "text/javascript",
                "file" : "script/createUnixHomeDir.js"
            }
        }
    ]
}

Often, script files are reused in different contexts. You can pass variables to your scripts to provide these contextual details at runtime. You pass variables to the scripts that are referenced in configuration files by declaring the variable name in the script reference.

The following example of a scheduled task configuration calls a script named triggerEmailNotification.js. The example sets the sender and recipient of the email in the schedule configuration, rather than in the script itself:

{
    "enabled" : true,
    "type" : "cron",
    "schedule" : "0 0/1 * * * ?",
    "persisted" : true,
    "invokeService" : "script",
    "invokeContext" : {
        "script" : {
            "type" : "text/javascript",
            "file" : "script/triggerEmailNotification.js",
            "fromSender" : "admin@example.com",
            "toEmail" : "user@example.com"
        }
    }
}
Read a different version of :