---
title: Script on connector operation
description: Connectors continue to be released outside the IDM release. For the latest documentation, refer to the OpenICF documentation.
component: pingidm
version: 7.2
page_id: pingidm:connector-dev-guide:operations/operation-script-on-connector
canonical_url: https://docs.pingidentity.com/pingidm/7.2/connector-dev-guide/operations/operation-script-on-connector.html
section_ids:
  ScriptOnConnectorApiOp-api-level-rules: Use the OpenICF script on connector operation
  ScriptOnConnectorOp-spi-level-rules: Implement the script on connector operation
---

# Script on connector operation

|   |                                                                                                                                                                                   |
| - | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|   | Connectors continue to be released outside the IDM release. For the latest documentation, refer to the [OpenICF documentation](https://docs.pingidentity.com/openicf/index.html). |

The script on connector operation runs a script in the environment of the connector. This is different to the script on resource operation, which runs a script on the target resource that the connector manages.

The corresponding API operation (`scriptOnConnectorApiOp`) provides a minimum contract to which the connector must adhere. (Refer to the [javadoc](../../_attachments/apidocs/org/identityconnectors/framework/api/operations/ScriptOnConnectorApiOp.html) for more information). If you do not implement the `scriptOnConnector` interface in your connector, the framework provides a default implementation. If you intend your connector to provide more to the script than what is required by this minimum contract, you must implement the `scriptOnConnectorOp` interface.

## Use the OpenICF script on connector operation

The API operation allows an application to run a script in the context of any connector.

This operation runs the script in the same JVM or .Net Runtime as the connector. That is, if you are using a local framework, the script runs in your JVM. If you are connected to a remote framework, the script runs in the remote JVM or .Net Runtime.

Consumption of the ScriptOnConnector operation, at the API Level

```java
@Test
public void runScriptOnConnectorTest() {
    logger.info("Running RunScriptOnConnector Test");
    final ConnectorFacade facade = createConnectorFacade(BasicConnector.class, null);
    final OperationOptionsBuilder builder = new OperationOptionsBuilder();
    builder.setRunAsUser("admin");
    builder.setRunWithPassword(new GuardedString("Passw0rd".toCharArray()));

    final ScriptContextBuilder scriptBuilder =
            new ScriptContextBuilder("Groovy", "return argument");
    scriptBuilder.addScriptArgument("argument", "value");

    Object result = facade.runScriptOnConnector(scriptBuilder.build(), builder.build());
    Assert.assertEquals(result, "value");
}
```

## Implement the script on connector operation

The `scriptOnConnector` SPI operation takes the following parameters:

* `request` - the script and the arguments to be run

* `options` - additional options that control how the script is run

The operation returns the result of the script. The return type must be a type that the framework supports for serialization. Refer to the [ObjectSerializerFactory](../../_attachments/apidocs/org/identityconnectors/framework/common/serializer/ObjectSerializerFactory.html) javadoc for a list of supported return types.

Implementation of the ScriptOnConnector operation, at the SPI Level

```java
public Object runScriptOnConnector(ScriptContext request, OperationOptions options) {
    final ScriptExecutorFactory factory =
            ScriptExecutorFactory.newInstance(request.getScriptLanguage());
    final ScriptExecutor executor =
            factory.newScriptExecutor(getClass().getClassLoader(), request.getScriptText(),
                    true);

    if (StringUtil.isNotBlank(options.getRunAsUser())) {
        String password = SecurityUtil.decrypt(options.getRunWithPassword());
        // Use these to execute the script with these credentials
    }
    try {
        return executor.execute(request.getScriptArguments());
    } catch (Throwable e) {
        logger.warn(e, "Failed to execute Script");
        throw ConnectorException.wrap(e);
    }
}
```
