Workflow Soluiton

 View Only

Workflow Tutorial: C# Scripting 

Mar 17, 2008 12:14 PM

Time to look sharp if you want to C#! Impress your friends by throwing in a little code into your project! The purpose of this tutorial is to learn how to include C# code in your projects using the Scripting component.

Prerequisites: None

Objective: To create a project which imports workable C# code using the Scripting component.

Estimated time to complete: 30 minutes

Step 1: Create a New Project

To begin, create a new Decision Only project. The composer project can be selected from the main page when you first run Workflow Designer.

Step 2: Add Necessary Components

To begin, click the Import Components button, located under your toolbox. In the window which appears, select Scripting.dll from the list. Click the Add button to select this library for inclusion. Click the OK button to perform the import.

Drag-and-drop a ScriptedComponent to your project model. This component is located under the Infrastructure / Scripting category within your toolbox. Connect your ScriptedComponent to your StartComponent and EndComponent.

Your model should initially look like the one displayed below:

Step 3: Setting Input and Output Data

For your project to work properly, you must set input and output variables. To begin, click the Input Data entry in the Project Info box on the left-hand side of your window.

In the window which appears, click the Add button to create a variable:

Set the new variable's name to "inputTxtNameArray", its type to "Text," and check the Array checkbox.

Click on the Output Data entry in the Project Info box. In the window which appears, click the Add button to create an output variable:

Set the new variable's name to "outputTxtEmailArray", its type to "Text," and check the Array checkbox.

Step 4: Complete Project Setup

Return to your main project's model by clicking on the Model: Primary tab at the top of the screen. Double-click on your Scripted Component. The Edit Scripted Component window should appear:

Click the Add button to create a new input parameter for your Scripted Component. Set the input parameter's name as "inScrTxtName", set its type to "Text", and check the Array checkbox.

Click the Edit Parameter Mappings button. In the window which appeats, select the Value from Data field, and click the ... button to the right of the Value from Data field. In the window which appears, select teh "inputTxtnameArray" variable, and click the OK button.

Click the OK button twice to accept changes. In the Edit Scripted Component window, click the Next>> button to continue in your specifications.

In the second step, enter "outputTxtEmailArray" into the Result Variable Name field, and select the Data Type as "Text." Also, check the Is Array checkbox:

Click the Next>> button to continue. In the third step, Source Code, enter the following snippet of code:

int i = 0;

foreach (String a in inScrTxtName) {

  inScrTxtName[i] = a + "@transparentlogic.com";
  i = i + 1;

}
return inScrTxtName;

Click the Next>> button to continue.

In the final step, step four, you may wish to test your code. To test your code, simply click on the run test button. If you wish to make sure you entered your code correctly, you may view it by clicking the view full source code button. To finish specifying your Scripted Component, simply click the Finish button.

Step 5: Edit the EndComponent

In the main model, right-click on the EndComponent and select Edit Component. In the Edit Component window, click on the ... button to the right of the Mapping field.

In the Edit Data Mapping window, select Value from Data and click the ... button to the right of the Value from Data field.

Select the variable "outputTxtEmailArray" from the Select Variable Name window, and click the OK button:

Step 6: Run and Test Your Project

Run your project by clicking on the Debug button on the toolbar. The Debug button appears as a bug with a green arrow over it.

In the window which appears, double-click on the blue Execute link.

Your project will initially ask you for input data:

Enter a name in the Value field, and click the OK button. Your project will execute. The results of your project will be displayed in the Execution log once execution is complete:

Finished!

Statistics
0 Favorited
3 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.