ConnectorLib .NET 24.2

# Implement Custom Actions

You can implement custom actions in a ConnectorLib .NET connector.

Action | Description | Method to override
--- | --- | ---
`action=MyAction` | Perform custom actions on a repository. | `Custom`

To implement a custom action, override the `Custom` method on the `ConnectorBase` interface.

The ``Custom`` method is passed the name of the action that was called in the request. The name is always in upper case, because action names are case-insensitive. You can use the `custom` method to handle as many action names as necessary, however the action names `FETCH`, `VIEW`, `GETURI`, `GETSTATUS`, and so on, are reserved by the connector for the standard actions.

The `Custom` method is also passed an `ICustomTask` object. This provides access to a request object that provides all of the action parameters. You can obtain the request object by accessing the property `Request` on the `ICustomTask` object.

NOTE: All actions require a configuration file section name for the action to run. For a synchronous custom action, this is taken from the `configsection` parameter in the request (for example `MyActionSection` in the request `action=MyAction&configsection=MyActionSection`). If `configsection` is not set the connector uses the value of the `sectionname` parameter. If neither of these action parameters are set the connector uses the section name `Default`. In this case, the connector logs the following warning:

`WARNING: Custom action is not associated with a configuration section, using [Default] section`

The section name is available through the `I` `CustomTask` object. Standard operations that read the configuration file use the correct section automatically.

Your code must use the parameters from the request to perform the action and populate the action response. Obtain the response object by accessing the property `Response` on the `ICustomTask` object. You can then call the method `SetValue(name, value)` on the response object to add an XML element and value to the response.

You can add attributes and nested elements to the action response using XPath-like expressions with element indexes. For example:

           Response.SetValue("document[0]/metadata[7]/@name", "MyField");

Your implementation of the custom method should return `false` only if the action name is not supported. In all other cases, return `true`. If another failure occurs then throw an exception from the `custom` method, giving the reason for the failure.

The following sample code shows how a custom action might be implemented for a basic connector. This example reads the action parameters that were set and writes them to the response.

           override public bool Custom(String action, ICustomTask task)
           {
              if (action != "ECHO")
                 return false;

              task.Log.WriteLine(LogLevel.Always, "Custom action " + task.Request.Action + " called");
              foreach (String param in task.Request.Parameters)
              {
                 task.Response.SetValue(param, task.Request[param]);
              }
              return true;
           }

Copyright 2024 Open Text
Version 24.2 | Last updated March 2024

Send documentation feedback

Close

Send documentation feedback

To send feedback using your default email client, open an email window.

Otherwise, send your feedback and the information below to MFI-swpdl.idoldocsfeedback@opentext.com.

We appreciate your feedback!

Product: IDOL ConnectorLib .NET 24.2

Topic Title: Implement Custom Actions