This is a how-to post that I intend to refer back to from time to time. The goal is to create a simple Application Engine program into which we can drop some PeopleCode and see how it works. Assuming we don’t need any of the online pieces, this is much easier than going through all of the steps to create a page and register it so we can see it online.
Step 1: Create a new Application Engine Program
In Application Designer, click Ctrl + N or use the File > New menu option. This will open the “New” dialog, and you can choose Application Engine program from the list.
You new program should look like this:
Step 2: Disable Restart
This step is very important. If you don’t disable the restart and your program crashes, you will have to go through a few extra steps before you can rerun it.
First, click on the properties button while your program is in focus (you can also use the File > Definition Properties menu):
This should bring up the Properties dialog. Then, go to the Advanced tab. Check the “Disable Restart” option.
Step 3: Add an Action
First, click on the “Step 1” step to select it. I usually click anywhere in the gray, and this should turn it black.
Next, click on the Add Action button, or you can use the Insert > Action menu.
Finally, change the type from SQL to PeopleCode.
Step 4: Save the program
At this point, you need to save before you can add PeopleCode. You can use Ctrl + S, click on the Save icon on the toolbar, or you can use the File > Save menu.
Step 5: Enter the PeopleCode
First, open the PeopleCode program by double clicking anywhere on the gray of the PeopleCode action. Or, you can right click on it and choose the “View PeopleCode” option.
Next, you will probably want to open a file to show output from your PeopleCode testing. You can use this PeopleCode:
Local File &log; &log = GetFile("c:\temp\log.txt", "W", "A", %Filepath_Absolute);
Then, you can print to that file with the writeline() method. For now, we will just print Hello, World.
Finally, you will probably want to close your file:
Here is what it all looks like:
Make sure to save once you make these changes.
Step 6: Run the Program
Again, after you have saved, go back to the main program window where you can see the Main section, Step 1, and your new PeopleCode action. Then, click the run icon.
In the dialog, Check the Output log to file and uncheck Run Minimized. The output log to file allows you to see what happened. Otherwise, the window will close before you see what happened. The run minimized isn’t a big deal, but if the program doesn’t run minimized you see it pop up and go away better. When the program goes away, you know it is done running.
Finally, when it is done, check the output. If you used the paths that I did your output should be in the c:\temp directory. You should have two files. The first, is the main output from the program. Check this to make sure the program ran to success:
The second is the log that your PeopleCode created. For now, it should just say, “Hello, World”.