Integration developers can create a library of common or useful code functions to use in their integrations. Shared libraries are available to all integrations within a communication plan, and are included when exporting and importing a plan.
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 integration in your communication plan 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.
- On the Integration Builder tab, in the Shared libraries area, click Add.
- If you have already created a shared library, or if you are working on an imported integration that includes shared libraries, expand the list, and then click the name of the library you want to modify.
- In the transformation script editor, in the list of script components on the right side of the screen, click the name of the library you want to modify, or click Add Shared Library to create a new one.
- On the Integration Builder tab, click the name of an integration to view its details, and then click Open Script Editor.
- If the code you want to share is already part of the transformation script, select the code in the editing pane.
- Click the Add Shared Library button at the bottom of the component list on the right side of the screen.
- Any selected code is automatically copied to the new shared library:
- If you created a new empty library, it will have a default name and contain default instructions about how to create functions in a shared library and use them in a transformation script:
- 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.