Getting started: Creating a Script

Let us create a script that converts names and addresses from an XML file to an Excel sheet.

Start Djuggler, from the menu choose New. Djuggler now creates an empty script. Save it directly by choosing Save from the menu, choose a folder and name the file "Creating a script". You now have an empty script, saved under its own name. We will now build the script step by step.

Creating Sources and variables

We are going to need some sources and variables to carry the data we will transport. It is a good idea to create them as soon as possible, as they will be needed in the actions we are going to use. At the start of a task you cannot always see in advance which and how many variables you will eventually need. Therefore, you can also create variables if you are editing an action. We will show that later. For now, we will create a Text File source up front since we want to read a text file containing the addresses we want to move to Excel.



To insert a Text File source, click the Text File icon below the Variables & Sources window, as shown above. You can also from the menu choose Variables|New Source|Text File. This will have the same effect. You will see a dialog where you can set the name of the source, for now, leave it at "TextFile1" and just click OK. You will see the new source appearing in the Variables & Sources window.

Next, we will insert our first action. From the Actions window to the left, open the Text Files category, and double-click the Open Text File action. You will see the action being inserted into the Script window. The result should now look like the screen shown below.



The Open Text File action will not yet be able to execute, we need to tell the action what text file source to use and where to find the file on your hard disk. You can try running the script by clicking the Run button; Djuggler will then complain that a source or variable is missing. So, what we will do now, is edit the action and prepare it to read the file we want. To do so, double-click the action in the Script window to bring up the Properties window.

The Properties window lets you set and edit the variables and sources an action needs. Also, it gives you help on the action to explain what the action does. The next screen shows the Properties screen opened.



As you can see, there are two properties that need to be set in the Open Text File action. Also, note the help text. You can also open an example script for this action - but be careful, this will replace the script you are currently editing (you will be asked to save that first, however). We have dropped down thee edit box by using the arrow button at the end. The drop down shows the source that we create before, TextFile1. The drop down also gives the option to create a variable on-the-spot, but for now we will choose TextFile1.
Next, we will fill in the filename and path where we stored our addresses. In this case, the file resides in c:\ and is called addresses.txt. We will fill in name and path in the Filename property by clicking the edit box next to Filename and typing the name manually. With all this done, the Properties window should look like this:



That is just fine, we can close the Properties window now. If we would execute the Open Text File script line now, it would place the file content in the TextFile1 source. That means we can handle the content using that source. The text file contains the following content.

<person>
  <name>John</name>
  <address>main road 1</address>
</person>
<person>
  <name>Annie</name>
  <address>high street 2</address>
</person>

We would like to read names and addresses, and place them into separate columns in an Excel sheet. There will be more than one address, so we need a loop. From the Loops category, we insert action Loop. Inside the loop, we will look for names and addresses. The source TextFile1 will have the xml content which we will search through with actions from the Source Text Manipulation category. Choose the Find Text in Source action and insert it into the loop. We have the following script now



Double-click the Find Text in Source action to edit this action. Set the Source property to TextFile1, and Text To Find property to "<name>". This will make this action look for the text "<name>" in the XML source from TextFile1. The action will move the text cursor just before "John" in the XML source (check the file content above. We do this so we can start reading the name from that position.



Reading the name is done with the Copy Text from Source action. Insert the action and double-click it to bring up its properties. The Copied Text property needs a new text variable. This variable is needed to stored the text we will copy. Create the variable on-the-fly by choosing, from the drop-down, "> New text variable", as is shown below. Fill the other properties as shown below as well (Source & Read Until). Then click Done.



Now notice that a new variable called "Name" is created in the Variables & Sources window.



We now have created two action that together will read a name from the XML source. We will create two more to also read the address. We will search for the text "<address>" with another Find Text in Source action. Then we will read the address with another Copy Text from Source action. We will copy the address until we reach the text "</address>".

Then we want to store the Name and Address we have just read into a DataGrid. We create a DataGrid source and use the next actions. First, we insert Append Data Row to add a fresh new row to the DataGrid. The we write data to it by using the Store Variables action. The result is as below.



Lets reflect a moment what we have achieved with this script. We have created two variables, Name and Address. We search for name data first, read it, then search for address data and store that as well. Once we have read both variables, we store them in a new row in the datagrid. The loop makes sure that subsequent persons are read as well. This loop will continue for ever, so we need to exit it when we can't read a new name anymore. This is done as follows; we look to see if the Name variable is not filled by checking if it is empty:



Almost done now! We will now save the DataGrid in an Excel file by adding a last action, Save Data File. View the complete script below.



Next, we will want to execute this script and see its workings and the final resulting Excel file. This is handled in the next section.