Snippets are small sections of Project logic that can be reused across multiple workflows. They are a way to make consistent changes across multiple Projects. This saves time and ensures quality when the same actions can be repeated through several Projects. Snippets can contain just a few lines of logic or can be much more complex if needed.
Error reporting is one common use for Snippets. Here is an example with a Module that sends an email to an administrator. The email will have the error message and job log attached:
Creating the Snippet
To implement this into some current Projects so that if they fail an email alert will be received, here are the steps. First, we need to get the XML that we will be working with. You can click the
Show XML button in the Project to view the code and copy the relevant section. Here, we will grab everything inside of the
Copy this code into a text document. Now, you will need to add the
<importFile> tags to the beginning and end of the XML. Save the file as an XML with any name you like and place it in a location where it will be accessible by the GoAnywhere MFT application.
Implementing the Code
After saving the file, go back into GoAnywhere and find a Project to use with the Snippet. In this example, our Snippet is a Module that will report errors with an email, so a Project was created ahead of time that will intentionally throw an error. The file that is specified in the Search and Replace Task does not exist, but the Project will not know that until it runs and looks for it.
Go to the Component Library and find the Import Project Source Task. Since our Snippet in this example is encompassing a Module, we will add it under the Project Component. Browse to the location of the Snippet or enter the path manually.
In this example, we want the Project to call our Module in the Snippet when an error occurs, so we’ll go to the Project Component and set
On Error – call:OnError.
Validate the Project to save it and ensure it compiles correctly. Once it is confirmed that everything is fitting together correctly, we can go ahead and run the Project. The job starts to run and encounters an error, so it calls the
OnError Module in the Snippet. The email is received with the information we set up:
Snippets also allow you to make quick changes to any Projects that are using the file. Here, we can simply change the wording of our email alert, and it will be reflected in all the workflows where the Snippet is used.