Integration developers can create a library of common or useful code functions to use in their integrations. Shared libraries are available to all inbound and outbound integrations in a workflow, and are included when exporting and importing.
For example, you might create a function that retrieves the user ID of an xMatters user. Instead of including the entire function code in each integration, you can add a "getUserID" function to your shared libraries, and call the function from the transformation script in any inbound or outbound integration in your workflow as though it was still part of the original script. If you need to update the function later, you only have to modify it in a single location.
If you have functions or other code in a separate application or text file, you can add a new shared library directly from the Integration Builder tab. You can also add and manage your libraries while working in the transformation script editor.
For more information using shared libraries in transformation scripts, refer to the Integration Builder scripting reference.
There are a couple of ways you can access the shared libraries depending on where you are in the process.
First, any existing shared libraries are listed on the Integration Builder tab. Click the Configured link to expand the list, and then click the name of a shared library to open it in the script editor.
Second, if you're in the transformation script editor, any shared libraries are listed on the right side of the screen. Click the name of the shared library item to open it in the script editor. It opens beside the transformation script you already have open.
- On the Integration Builder tab, click the name of an integration to view its details, and then click Open Script Editor.
- Do one of the following to create the shared library:
- If the code you want to add to a shared library does NOT exist in the transformation script, click the Add Shared Library button on the right side of the screen to create a new empty library. The shared library has a default name and default instructions about how to create functions in a shared library and use them in a transformation script.
- If the code you want to share DOES exist in the transformation script, select the code in the editing pane, then click the Add Shared Library button. Any selected code is automatically copied to the new shared library:
- Add or modify the code as required.
- If you copied existing code to create the new shared library, you may want to delete the code from the original script to avoid potential conflicts.
- Click in the title area and type a name for the new shared library.
- The name is used to reference the shared library from within transformation scripts, and to identify the shared library in the list and on the Integration Builder tab.
- Click Save to create the new shared library.
- To view the contents of a shared library, move the pointer over its name in the list.
- Click Hide to close the shared library pane.
When you are creating and managing shared libraries from the Integration Builder tab, the interface does not display your existing integration transformation script code:
For more information about referencing functions from a shared library in your transformation script, see Shared library functions.
- To edit an existing shared library, click its name in the list on the Integration Builder tab, or within the script editor, and then modify its details.
- Click Save.
The save button is enabled when there are unsaved changes in your shared library.
To delete a shared library, click the X beside its name in the Shared libraries area on the Integration Builder tab, and then click Delete Shared Library.
If you have a function in a transformation script with the same name as a function in a shared library, the integration may not call the correct one (or the same one every time), leading to unexpected and unpredictable results. Use a unique name for each of your shared libraries.