- Workflow Organization
- Workflow Concepts
- Modifying the Built-In Workflows
- Creating New Workflows
- Workflow Scheduling
- Summary
Modifying the Built-In Workflows
- Development of the mind can be achieved only when the body has been disciplined. To accomplish this the ancients have taught us to imitate nature.
- —Kahn, Kung Fu
Like imitating nature in Kung Fu, Workflow-Fu is also best learned by imitating the workflows that come built in to vCO. We spend a good deal of time copying and modifying workflows in Part III of this book. However, there is a basic process to editing workflows that will make your workflow-building life much easier.
In our example, we modify the “Export Logs and Application Settings” workflow as shown in Figure 6.2 to send the resulting application logs via email to a defined user.
Figure 6.2 “Export Logs and Application Settings” workflow
To do this, follow these steps:
- Duplicate the workflow.
- Edit the workflow.
- Edit the schema.
- Edit the user interaction.
- Edit the script.
- Validate the workflow.
Duplicate the Workflow
To duplicate the workflow, right-click the workflow from Figure 6.2 and select duplicate workflow. From there, choose a name and new location for this workflow, as shown in Figures 6.3 and 6.4, respectively.
Figure 6.3 Duplicating the workflow
Figure 6.4 Selecting the workflow destination
Edit the Workflow
To get into the workflow editor, right-click the newly created workflow, and then click Edit. The resulting workflow editor is shown in Figure 6.5.
Figure 6.5 Workflow editor
Our first order of business is to edit the description to something that more closely reflects what our end result will be. Then, we must add an input to allow email to flow.
Edit Schema
Now we need to edit the schema of the workflow to add our extra email task. This requires a few steps:
- Add user input.
- Add a scriptable task.
- Edit new elements.
Let’s look at an actual example. Figure 6.6 shows the user inputs being added.
Figure 6.6 Adding inputs
Figure 6.7 shows the schema editor.
Figure 6.7 Schema Editor
Our first order of business is to add the user input task. To do this, select the link between the workflow start and the Export task, as shown in Figure 6.8.
Figure 6.8 Link selected
Then, right-click and select Insert element, User Interaction Task, as shown in Figure 6.9.
Figure 6.9 Insert user interaction
Then, we add in a scriptable task to send the email. To do this, select the link between Export and the workflow stop, as shown in Figure 6.10.
Figure 6.10 Link selected
With the link selected, right-click and select Insert Element, Scripting Task, as shown in Figure 6.11.
Figure 6.11 Inserting scripting task
Figure 6.12 shows the resulting workflow.
Figure 6.12 Final workflow
Edit the User Interaction
We need to edit the default input task to populate the emailAddress attribute that we will use in the scriptable task. To do this, select User Interaction; once that is selected, we work across the bottom tabs, starting with the Info tab, as shown in Figure 6.13.
Figure 6.13 User Interaction, Info tab
The next tab that we’re interested in is External Inputs. In this tab, you want to press Ctrl+B to open the Chooser window. From there, select the Create parameter or attribute link to the right of the search box. Figure 6.14 shows the resulting window.
Figure 6.14 emailAddress attribute bound to user interaction task
From there, click OK and save the workflow, and select the Scriptable Task task.
Edit the Scriptable Task
Now comes the fun part, adding the email script. We have a few tasks to sort out before we get into the meat of the script, however. We’ll work our way left to right using the tabs in the bottom window pane.
First, we rename the scriptable task to “Email Logs,” as shown in Figure 6.15.
Figure 6.15 “Email Logs”
Next, we add parameters to the task. We add both emailAddress and localPath to the task, enabling us to get at both the file and the email address. To do this, select the In tab and press Ctrl+B. Figure 6.16 shows the results.
Figure 6.16 emailAddress and localPath added to script task
Next, we select Scripting and add the following script:
var message = new EmailMessage(); var content = "vCO Logs Attached"; message.toAddress = emailAddress; message.subject = "vCO System Logs"; message.addMimePart(content,"text/html; charset=UTF-8"); message.addMimePart(localPath,"application/zip"); System.log( "sending mail to host: " + message.smtpHost + ":" + message.smtpPort + " with user:" + message.username + ", from:" + message.fromAddress + ", to:" + message.toAddress ); message.sendMessage();
This is the code to create and send email with vCO logs attached.
The code creates an EmailMessage type scripting object, checks to see whether other email server parameters have been provided, and finally builds the message using our attributes as specified earlier.
Figure 6.17 shows starting the workflow, done by right-clicking the workflow and clicking Start Workflow. When launching the workflow, vCO automatically validates the workflow to ensure that it will run. Therefore, if you receive any errors when starting the workflow, it is because validation failed; so, you need to go back and correct something within the workflow.
Figure 6.17 Email with vCO logs attached