HowTo AppEngineTutorial Ex4

Embed Size (px)

Citation preview

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    1/21

    Application Engine

    Exercise #4: Dynamic Call Sections and PeopleCode

    Found at and downloaded from: https://projectweb.cc.unt.edu/EISDeveloper/Shared%20Documents/Training%20Materials/AppEngine%20Exer%204.doc

    These Messages will need to exist in your database.PeopleTools-->Utilities-->Administration-->Message CatalogMessage Set: 20101Msg #4 The three values entered are: %1, %2, %3.

    Msg #5 Of the three numbers entered, the FIRST number (FIELD1) has the highest value: %.Msg #6 Of the three numbers entered, the SECOND number (FIELD2) has the highest value: %.Msg #7 Of the three numbers entered, the THIRD number (FIELD3) has the highest value: %.Msg #8 All three numbers entered are the same value. No HIGH value found.

    In this exercise, you will create a simple AppEngine program that uses PeopleCode todynamically call a section based on three numbers input by the user.

    I. CREATE THE PROJECTFirst, you will need a project. You may open an existing project or create a new one.

    II. CREATE THE STATE RECORDYou will need a state record to hold the runtime parameters (three numbers) entered by theuser.

    The first thing you should do is create the state record to be used in this exercise.

    1. Click on File, New or click on .

    2. Click on Record and then click OK

    3. The key field (and the only key field) for a state record should be the field calledPROCESS_INSTANCE (do not use the field PROCESSINSTANCE). To insert thefield into your record, on the menu bar click on Insert, then on Field

    4. Type the entire name of the field in the Name box and click on Insert, ortype a partial name in the Name box and press ENTER to get a list to choose from.Then either double-click the field you want to insert or click on it once to highlight andclick on Insert.

    Page 1 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    2/21

    5. Now your record has one field in itPROCESS_INSTANCE.

    6. You will need a field on your state record for each of the three numbers entered by theuser. You can use the existing fields FIELD1, FIELD2, and FIELD3 for this exercise (orcreate your own new fields).

    7. You will also need a field to store the name of the section that will be called dynamically.You should use the delivered field AE_SECTION for this.

    Page 2 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    3/21

    8. Lastly, you need a field to indicate that no single number of the three entered by the userwas highest. You will use this flag to put out a message indicating that no single numberwas highest. You can use the existing field NO_HIGH_FLAG for this exercise (or createyour own new field).

    9. When completed, your state records should look something like this (note that

    PROCESS_INSTANCE has been set as the key):

    10. Now you need to save your state record definition. Click on File, Save As or Click on. Type a name for your state record (please follow established naming conventions

    explained in UNTSP Standards document found in the Shared Documents section ofthe EIS Developer Forum website), then click on OK (or press ENTER).

    11. You must build the record since this will be a physical SQL table. With the recorddefinition open on the screen, click on Build, then on Current Object.

    12. Verify that the boxes for Create Tables is checked and the radio button for Executeand build script is selected, then click on the button labeled Build.

    Page 3 of 21

    Save AsCOA_AETUTOR_AET

    GBUT_xx_EX4_AET

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    4/21

    III. CREATE THE APPLICATION ENGINE PROGRAMNow you are ready to create the program.

    1. Click on File, New or click on

    2. In the New window first choose an Object Type of App Engine Program, then clickon OK.

    3. You should now see a skeleton AppEngine program containing a MAIN section andone step labeled Step01 displayed in the Object workspace

    4. Open the AppEngine Program Properties window:

    a. Click on orb. Click on File, Object properties orc. Press ALT-ENTER on your keyboard

    5. Click on the Advanced tab and check the Disable Restart box. It is important todisable restart of a program while testing to prevent problems with rerunning the job.

    Once the program is tested, Disable Restart may be unchecked to test restartprocessing. Click OK to close the Program Properties window.

    Page 4 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    5/21

    6. Now, save this AppEngine program with a new unique name. Click on File, Save As.Type a unique name for your program (please follow established naming conventionsexplained in UNTSP Standards document found in the Shared Documents section ofthe EIS Developer Forum website), then click on OK (or press ENTER).

    7. Now you need to add some Actions to your program (so it will actually do something!).To insert an Action (without inserting another Step along with the Action), either

    d. Right-click on the area to the left of Step01 and click on Insert Action. or

    e. Click once on Step01 to highlight it and click on

    Page 5 of 21

    Save AsCOA_AE_TUTORGBUT_xx_EX4

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    6/21

    8. The default action is SQL. That is what we want.

    9. Double-click in the area to the left of the SQL action to open the SQL Editor.

    10. The SQL needs to populate the fields in your state record using a %Select (meta-SQL)command since you will be using a custom run control record and page (you will createthese later in the exercise). The SQL should look like this:

    %Select(FIELD1, FIELD2, FIELD3)SELECT FIELD1, FIELD2, FIELD3FROM PS_COA_AETUT_RNCTL

    WHERE OPERID = %OperatorIdAND RUN_CNTL_ID = %RunControl

    11. Click on to check the syntax of the SQL statement. Important note this will notvalidate that your SQL is correct (i.e., correct table name, correct field names, etc). Itwill only reformat your SQL the way it wants it to look. Misspelled names or misplaced

    commas or parentheses will cause runtime errors.

    12. Close the SQL editor window.

    13. Save your program again.

    14. Now add another Action within Step01 bya. right-clicking on the area to the left of the SQL action and clicking on Add

    Action or

    Page 6 of 21

    Right-click in this area

    and click on Insert Action

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    7/21

    b. by clicking once on the SQL action to highlight it and clicking on the Insert

    Action button on the toolbar

    15. This new action should be Log Message so choose that from the drop-down box. Thisaction will write out a message indicating the three numbers the user input. A messagehas already been setup in the Message Catalog so use message set 20101, message

    number 4. The parameters should be set to:

    %Bind(FIELD1), %Bind(FIELD2), %Bind(FIELD3)

    16. Now add another Step/Action within sectionMAIN. The new action should bePeopleCode so choose that from the drop-down box. This action must be placed in aseparate step because the order of execution within a step (see the Application Enginetraining manual or PeopleBooks for details) would cause the PeopleCode action to beexecuted before the SQL action (which would not work because your state record hadnot yet been populated with the numbers your are checking!).

    17. Double-clickin the area to the left of the PeopleCode action to open the PeopleCodeEditor.

    18. Type the following code:

    COA_AETUTOR_AET.NO_HIGH_FLAG = "N";If COA_AETUTOR_AET.FIELD1 > COA_AETUTOR_AET.FIELD2 And

    COA_AETUTOR_AET.FIELD1 > COA_AETUTOR_AET.FIELD3 ThenCOA_AETUTOR_AET.AE_SECTION = "Message1";Exit (0);

    ElseIf COA_AETUTOR_AET.FIELD2 > COA_AETUTOR_AET.FIELD1 And

    COA_AETUTOR_AET.FIELD2 > COA_AETUTOR_AET.FIELD3 ThenCOA_AETUTOR_AET.AE_SECTION = "Message2";Exit (0);

    ElseIf COA_AETUTOR_AET.FIELD3 > COA_AETUTOR_AET.FIELD1 And

    COA_AETUTOR_AET.FIELD3 > COA_AETUTOR_AET.FIELD2 ThenCOA_AETUTOR_AET.AE_SECTION = "Message3";Exit (0);

    ElseCOA_AETUTOR_AET.NO_HIGH_FLAG = "Y";Exit (1);

    End-If;End-If;

    End-If;

    This code initializes the flag to indicate that no one number was higher than the others

    to N, tests to see which of the three numbers is higher and sets AE_SECTION to thesection of the program you want to call (youll create these sections next) or sets the flagto Y if no single number is highest. The important part of this code is that by settingAE_SECTION to a literal (which must match a section name in your program to work),the AppEngine program is able to dynamically decide the execution path. Using Exit(0)and Exit(1) also controls the program flow by determining whether to perform theOnReturn action for the PeopleCode action or not. Zero (0) tells the program to ignorethe OnReturn action. One (1) indicates that the instruction will be followed. In this

    Page 7 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    8/21

    PeopleCode action you want the OnReturn to be set to Skip Step. This will make moresense after you add the next action.

    19. Now you need to add another action to the step containing the PeopleCode action.This action should be Call Section and you should check the box labeled Dynamicbecause you will not specify which section to call, the PeopleCode in the previous

    action will decide that for you. When the Dynamic box is checked, the AppEngineprogram knows to look for AE_SECTION in the state record to determine the section tobe called.

    20.Save your program again.

    21. Now you need to add the three sections that could possibly be called from the dynamicCall Section action.

    a. The first new Section will be inserted with a default name of Section1. Changethe name of the section to Message1.

    Important note: You must name the section exactly the same as what you used in yourPeopleCode including case. Setting AE_SECTION to Message1 and then naming thesection MESSAGE1 will cause problems!

    b. Add a Step and an Action to the new section Message1.

    c. Change the action to Log Message. Use Message Set 20101 and MessageNumber 5. Parameters are %Bind(FIELD1).

    d. Repeat steps a through c for Message2 (use Message Set 20101 and MessageNumber 6, %Bind(FIELD2)) and Message3 (use Message Set 20101 and Message

    Number 7, %Bind(FIELD3)).

    22.The last aspect you need to handle is if no single number is highest. That will mean thatthe Call Section action in Step02 will not be executed because the AppEngine programwill exit out of the PeopleCode with Exit(1) which causes the instruction in theOnReturn box to be followed (which was Skip Step so the program exits the current Stepand continues processing at the next Step in the Section). So you need to add anotherstep to the MAIN section that will contain two actions.

    Page 8 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    9/21

    23.The first action in the new step (Step03) will be PeopleCode. The code will look like this:

    If COA_AETUTOR_AET.NO_HIGH_FLAG = "Y" ThenExit (0);

    ElseExit (1);

    End-If;

    Once again you are using the Exit command to control program flow. If the flag is set toY, then you want the program to flow normally (ignoring the instruction in theOnReturn box) to the next action you will add which is Log Message. If the flag is notY, then you want the program to skip the next action (Log Message) so you will usethe Exit(1) command to cause the instruction in the OnReturn to be followed (SkipStep). See the Application Engine training manual for more information on Skip Step.

    24.As mentioned above, the second action in the step will be Log Message. Use MessageSet 20101, Message Number 8. There are no parameters in this message.

    25. Save your program again.

    26.The last modification necessary is to link the state record you created to the AppEngineprogram. This is done in the Program Properties.

    Open the AppEngine Program Properties window:

    f. Click on org. Click on File, Object properties orh. Press ALT-ENTER on your keyboard

    27. Click on the State Records tab. In the box labeled Qualify Search, you can type apartial name or the full name of your state record and click on the button labeled Get

    List. DO NOT PRESS ENTERthat will close the Program Properties window.

    28.Click once on your state record to highlight it and click on the button labeled Add.You will now see your state record listed in the Selected window on the right. It isautomatically selected as the default state record because it is the only one you areusing. If you were using more than one state record with your AppEngine program, youwould continue to add then using the same process just described.

    Page 9 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    10/21

    When completed, your AppEngine program should look something like this (this is what itlooks like in Print Preview):

    Page 10 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    11/21

    Now, you are almost ready to test your AppEngine program! In order to run an AppEngineprogram, you must first create a custom Run Control Record, a custom Run Control Page, anda Component to contain the page. Notify your instructor when you are ready to have yourComponent added to a Menu and Security set for the Component.

    Please refer to Exercise #2 on procedures for creating a custom run control record and page.Your custom run control record must contain the following fields:

    OPRIDRUN_CNTL_IDFIELD1

    FIELD2FIELD3

    The following is from above referenced Exercise #2, pages 10-14

    Now, you are almost ready to test your AppEngine program! In order to run an AppEngineprogram, you must first create a custom Run Control Page that will accept input from the userand a Component to contain the page, add the Component to a Menu, and set Security for theComponent.

    Page 11 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    12/21

    IV. CREATE THE CUSTOM RUN CONTROL RECORDYour custom Run Control Page will require a custom Run Control Records. You can clone thegeneric Run Control Record delivered from PeopleSoft as a starting point.

    1. Open the Record PRCSRUNCNTL by either

    a. Click on File, Open or by clicking on

    The record will look like this:

    The fields OPRID and RUN_CNTL_ID are the record key fields. The LANGUAGE_CDand LANGUAGE_OPTION fields are used in global development projects and are notnecessary in our application.

    2. First, save this record with a new, unique name. Click on File, Save As. Type a uniquename for your program (please follow established naming conventions explained inUNTSP Standards document found in the Shared Documents section of the EISDeveloper Forum website), and then click on OK (or press ENTER).

    3. When prompted with the question Do you wish to also save a copy of the PeopleCodeassociated with PRCSRUNCNTL.ENG?, click on Yes.

    Page 12 of 21

    Save As using

    GBUT_xx_RNCTL

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    13/21

    4. Since we have no need for the LANGUAGE_CD and LANGUAGE_OPTION fields, deletethose fields. One method for deleting the fields is to right-click on the field and thenclick on Delete. Once the two fields have been deleted, save your record again.

    5. Now you need to add the field for which you will be accepting a parameter from the user.This field is GBUT_PCT_INCREASE. Add this field to the record as described

    previously in this document (see hyperlink Inserting a Field into a Record).

    6. Look for any Record PeopleCode that might exist from the source record definition andmodify any record or field names as necessary to match the names in this project.

    7. Save your custom run control record again. Then build the SQL table as describedabove (see hyperlink Building a Record).

    V. CREATE THE CUSTOM RUN CONTROL PAGELikewise, even though you will need to modify it to accept additional parameters and to use thecustom run control record you just created, you can still clone the generic Run Control Pagedelivered from PeopleSoft as a starting point.

    8. Open the Page PRCSRUNCNTL by either

    a. Click on File, Open or by clicking on

    Page 13 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    14/21

    The Page will look like this:

    9. The first thing you should do is save the page with a unique name. Click on File, SaveAs to save the Page under a different name (please follow established namingconventions explained in UNTSP Standards document found in the Shared Documentssection of the EIS Developer Forum website).

    10. When prompted with the question Do you wish to also save a copy of the PeopleCodeassociated with PRCSRUNCNTL.ENG?, click on Yes.

    Page 14 of 21

    Save As using page name ofGBUT_xx_RNCTL

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    15/21

    11. Next, you need to add the custom field to the page. The easiest way to accomplish that isto double-click on GB_xx_RNCTL from the project workspace window so that you cansee the individual fields on the record. Then drag-and-drop GBUT_PCT_INCREASEon to the run control page.

    12. Look for any Page PeopleCode that might exist from the source page definition andmodify any record or field names as necessary to match the names in this project.

    13. Save your page again.

    VI. CREATE THE COMPONENT FOR YOR RUN CONTROL PAGETo create a Component for your new custom Run Control Page:

    1. Click on File, New or click on

    2. Click on Component, then click on OK

    Page 15 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    16/21

    3. Expand the list of Pages in your project by clicking on the plus sign next to Pages in theProject workspace.

    4. Drag and drop the custom Run Control Page you created onto the Component.

    5. Before the Component can be saved, a search record must be specified. Click on toopen the Properties window and click on the Use tab. Since you have created a customrun control record, you should select it (GBUT_xx_RNCTL) as the search record, andthen click on OK.

    6. Click on File, Save or click on .

    7. Type a name for the Component (please follow established naming conventionsexplained in UNTSP Standards document found in the Shared Documents section ofthe EIS Developer Forum website) and click on OK. For this exercise, use the nameGBUT_xx_EX2.

    **** END OF EXERCISE 2 INSERT ****

    Page 16 of 21

    Drag and drop in the Object workspace

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    17/21

    VII. REGISTER THE COMPONENTOpen your COA_AETUTOR_CMPNT Component in App Designer

    Select Menu Tools-->Register ComponentCheck the three checkboxes to add component to: menu, portal registry, and permission list

    Click "Next"

    Select a City Menu Name, in this case I put it in "COA_SETUP"

    Select a Bar Name, in this case I selected "USE"

    Click "Next"

    Page 17 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    18/21

    Select "Target Content"

    Portal Name: EMPLOYEEFolder Name: COA_SETUP

    Content Reference Name: COA_AETUTOR_CMPNT_GBL_1

    Content Reference Label: COA AppEngine Tutorial

    Long Description: A test App Engine program for demo purposes.

    Sequence Number: Add the appropriate number (say 10)Product: PT

    Node Name: blankAlways Use default local node?: Checked

    Click Next

    Page 18 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    19/21

    Assign a permission list (I used COA_ALL)

    Check all the Page Action checkboxes (Add, Update/Display, etc)Click Next

    Check all the project Options Add to Project: Menu, Registry entry, Permission ListClick Finish

    Page 19 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    20/21

    The last step before you can run the AppEngine program youve created is to create a ProcessDefinition for the PeopleSoft Process Scheduler. This step must be completed whether you arerunning the AppEngine program two-tier, three-tier, or n-tier.

    VIII. CREATE THE PROCESS DEFINITION

    To create a Process Definition:1. On the web, navigate to PeopleTools > Process Scheduler Manager > Use > ProcessDefinitions

    2. Click on the hyperlink Add a New Value

    3. Click on the lookup icon and then click on Lookup4. Click on the hyperlink Application Engine5. Type in the Process Name This must match your AppEngine program name!6. Click on Add7. Click on the Process Definition Options tab8. In the Component section of the form, click on the Lookup icon and select your

    Component (this will be the Component that contains your Run Control Page)

    9. In the Process Groups section of the form, click on the Lookup icon and select thepermission list used with this AppEngine program (in this exercise use ALLPANLS)

    10. Click on Save

    IX. DEFINE THE JOB TO THE PROCESS SCHEDULERAfter the Process Definition has been setup, you need to define the JOB to process scheduler.

    Navigate to PeopleTools Process Scheduler ProcessesADD your App Engine program NAMESet security for the Component NameAssign process group to something like APALL

    Believe it or not, you are finally ready to run your AppEngine program!

    To execute your AppEngine program via the web:

    1. Navigate to the Menu Item you added. When you click the menu item a Run ControlSearch Page will be displayed.

    2. If you have an existing Run Control ID you want to use, you can type the name (orpartial name) and click on Find. If you want to add a new one, click on the hyperlinkAdd a New Value then type a value for the Run Control ID and click on Add. This canbe any value you wishit does not need to match the AppEngine program name and can

    be reused.

    3. When the Run Control Page is displayed, type in three numbers then click on Run.

    4. A page containing a list of all Process Definitions linked to this Component (viaSecurity) is displayed. Since the Process Definition name must match your AppEngineprogram name, this provides the link that PeopleSoft will need to know which programto run. Click on OK to submit the Process Scheduler Request.

    Page 20 of 21

  • 7/28/2019 HowTo AppEngineTutorial Ex4

    21/21

    5. The display will return to the Run Control Page and display your Process Instance. Youcan now click on the hyperlink Process Monitor to view the progress of your programexecution.

    6. Verify that the correct message was written to the message log based on the numbersyou entered.