Saflet101Invoke
Contents |
Invoking Saflets (subroutining)
Walkthrough
Download Saflet Used in this Walkthrough
For this walkthrough; you will need to be connected to a SafiServer (see Connection to SafiServer from SafiWorkshop).
You will also need to create a Project and 2 Saflets with the Custom Initiator selected as the starting initiator (See: Creating a Project and Saflet). Lets name them base.saflet and sub.saflet
For this walkthrough base.saflet will invoke sub.saflet
In sub.saflet add two variables named: myVar1 and myVar2 both with the type of Text and no initial value:
Add Input Parameter
Double click the initiator (in this case the CustomInitiator step). Press the plus (+) button to add a parameter. For the name enter myInput:
Press OK and select myVar1
Press OK
Add Output Parameter
Select the Outputs tab and press the plus (+) button. This is just like adding the input parameter: for the name use myOutput and select myVar2 for the variable. After added, the dialog should look like this:
Press OK. Your workspace should look like this:
Finish the sub.saflet
Add the following ActionSteps
- (1) DebugLog
- (1) Assignment
Connected like this:
For the DebugLog step set the Message field to the following script:
"sub.saflet passed a variable of: " + myVar1;
For the Assignment step set myVar2 to the following Value script:
myVar1 + "-changed";
Save and Publish the Saflet. Now switch to base.saflet
base.saflet
In base.saflet add two variables:
- myPassVar with the type of Text and an initial value of foo
- myReceivedVar with the type of Text and no initial value
- (1) DebugLog
- (1) InvokeSaflet (found under Logic)
Connected like this:
Double-click the InvokeSaflet step and click the edit button (...) on the Target Saflet field. This will bring up the Saflet chooser. Select sub by checking the box next to the name:
Press OK and OK again and you should see the Parameters auto-created in the InvokeSaflet step
Double click the myInput box and select myPassVar to assign
Double click the myOutput box and select myReceivedVar to assign
Finally, for the DebugLog step set the Message field to the following script:
"base.saflet received for myOutput: " + myReceivedVar;
Save and Publish the Saflet.
Launch the base.saflet using the Custom Initiator Launcher
You should see the following result in the Console pane
Initiator Hover Add Option
You can also add parameters by hovering over the initiator and select the "Add input parameter" or "Add output parameter" button (see illustration below)
SideBar
User Login
Comments (