How To

How do I write to a file using JavaScript on a custom endpoint in IDM/OpenIDM (All versions)?

Last updated Jan 27, 2020

The purpose of this article is to provide examples of writing to a local file using JavaScript® on a custom endpoint in IDM/OpenIDM. This article assumes you have already created your custom endpoint.

1 reader recommends this article


IDM/OpenIDM uses Mozilla® Rhino v1.7R4, which is an embedded Java® implementation of a JavaScript engine. This implementation allows you to execute JavaScript used by endpoints, inline code etc in IDM/OpenIDM.

Writing to a file using JavaScript examples

Here are two examples of how you can write to a file using JavaScript by calling Java from Rhino:

// Verify that the file exists and if not, create it
var fileObj = new"/path/to/myfile/file.txt");
if (!fileObj.exists()) {

// Create a filewriter object, then append a line to the file and close the file
var fileWriter = new"/path/to/myfile/file.txt", true); // true = append
var logData = "Test\n";

Or a more efficient version:

var content = new java.lang.String("some string" +

See Also

How do I load JavaScript functions into IDM/OpenIDM (All versions)?

How do I add logging to JavaScript files in IDM/OpenIDM (All versions)?

How do I debug server-side JavaScript code in OpenIDM 4.x?

FAQ: Scripts in IDM/OpenIDM

Integrator's Guide › Extending Functionality By Using Scripts › Creating Custom Endpoints to Launch Scripts

Samples Guide › Creating a Custom Endpoint

Connector Developer's Guide

Rhino documentation

Related Issue Tracker IDs


Copyright and TrademarksCopyright © 2020 ForgeRock, all rights reserved.