Showing posts with label Dynamically. Show all posts
Showing posts with label Dynamically. Show all posts

How to populate different messages from Message Catalog with dynamic list of parameters

How to populate different messages from Message Catalog with dynamic list of parameters
In this post we are going to look at how we will be able to populate different messages in message catalogue and pass different number of parameters (either using MsgGetExplainText or MsgGetText functions) dynamically.
This may come in handy as you define different messages for different purposes depending on the functionality you implement. These messages may be in the same message set and each message may require a different number of parameters to be passed in your PeopleCode program.
So in this case and depending on the context it may be good idea to define a function where you pass your message set, message number and parameter list (as a string array) and get the Explain Text or Message Text and display a message to the user.

Here is the example. In this function you can pass populated string array (as &ParmArray) and depending on number of parameters you want to populate in you message you can call this function and return the message text you want.

/* population of a message
&MsgSet The message set of the message
&MsgId the Message Id, based on the message set
&ParmArray the array of parameters for the message specified, if no parameters are needed null can be passed*/

Function messagetoString(&MsgSet As number, &MsgID As number, &ParmArray As array of string) Returns string   
   
   Local string &messageString = "";
   If (&ParmArray <> Null) Then
      Evaluate &ParmArray.Len
      When 0
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found");
      When 1
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1]);
      When 2
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2]);
      When 3
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3]);
      When 4
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4]);
      When 5
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5]);
      When 6
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6]);
      When 7
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7]);
      When 8
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7], &ParmArray [8]);
      When 9
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7], &ParmArray [8], &ParmArray [9]);
      When 10
         &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found", &ParmArray [1], &ParmArray [2], &ParmArray [3], &ParmArray [4], &ParmArray [5], &ParmArray [6], &ParmArray [7], &ParmArray [8], &ParmArray [9], &ParmArray [10]);
      End-Evaluate;
   Else
      &messageString = MsgGetText(&MsgSet, &MsgID, "Message Not Found");
   End-If;
   
   Return &messageString;
   
End-function;

Here I used MsgGetText function. Similarly you can use MsgGetExplainText as well.

How to dynamically populate data in a grid using SQL views

How to dynamically populate data in a grid using SQL views
PeopleSoft Grids are powerful page controls in PeopleSoft. It can display information in a spreadsheet format and you can embed other page controls such as buttons, drop-down lists, html areas, etc.. to the grid. You use grids depending your table structure and how your page will display to the users based on user requirements. Grids are used in occur Level 1, 2 or 3 and it depends on whether you have more than one underlying record definition on a page.

Sometimes you want to pull information from multiple records and display in a grid on a page.
Since, a grid can associate with only one primary record, you have to create a view to get data from one or more records. Then you can associate the view record as the primary record in the grid.
However, imagine that you want to populate the grid dynamically passing parameters to the view.
Since, views cannot accept parameters dynamically (unlike SQL definitions or dynamic views) how do you handle this kind of situation. You can achieve that with the help of Select method in Rowset class. Select, reads data from the database tables or views into either a row or rowset object.

A good example from PeopleBooks
The following example selects into the child scroll of the level one rowset.  Each row fetched is placed under the appropriate row in &LEVEL1.
Note that instead of hard-coding the WHERE clause, the SQL repository is used to access a SQL definition named SELECT_WHERE.

&LEVEL1 = &LEVEL0()(1).GetRowset(SCROLL.EMPL_CHECKLIST);
&LEVEL1.Select(SCROLL.EMPL_CHKLST_ITM, RECORD.EMPL_CHKLST_ITM, SQL.SELECT_WHERE);
Another way you can achieve this, by creating a function to accept dynamic parameters (to WHERE clause) and then calling that function in appropriate event to populate the grid.
Note that here we use rowset Flush method to remove all rows from the rowset and free its associated buffer before selecting to the grid.
Flush method is often used to clear a work scroll before using the Select method.

rem Function to Refresh the Grid;
Function RefreshMyGrid(&Param1, &Param2,..,&ParamN)
   &rs = GetLevel0()(1).GetRowset(Scroll.MY_GRID_VW);
   &rs.Flush();
   &rs.Select(Record.MY_GRID_VW, "WHERE MYFIELD1 = :1 AND MYFIELD2=:2, MYFIELDN=:N", &Param1,&Param2,&ParamN);
End-Function;

How to Dynamically Change Radio Button Labels using PeopleCode

How to Dynamically Change Radio Button Labels using PeopleCode
If you want to dynamically change the labels of a radio button on a page, you can use a new method in the field class: GetPageField.
The GetPageField method references a field by the unique page field name. The page field name is the name specified on the General tab in the page field properties in the page defintion;
Here is an example where you can change the radio button labels dynamically on a page;

Local boolean &amp;ChangeLables;
If  &amp;ChangeLables = True Then
    &amp;Fld_1 = GetPageField(Page.Page_1,"Radio_Button_1");
    &amp;Fld_2 = GetPageField(Page.Page_1,"Radio_Button_2");
    &amp;Fld_1.Label = "Label_1"
    &amp;Fld_2.Label = "Label_2";
End-if;

Another Example from PeopleBooks
The following example initializes four Field objects to four specific radio button page fields and conditionally sets their labels to either a long version or a short version.
&Fld1 = GetPageField(Page.GNNWG_PAGE, "INITIALIZE"); /* Initialize Radio Button */ &Fld2 = GetPageField(Page.GNNWG_PAGE, "COMMIT"); /* Commit Radio Button */ &Fld3 = GetPageField(Page.GNNWG_PAGE, "ROLLBACK"); /* Rollback Radio Button */ &Fld4 = GetPageField(Page.GNNWG_PAGE, "SAMFAIL"); /* SAMFAIL Radio Button */ If &amp;SetLabel = "Long" Then &amp;Fld1.Label = "Initialize_Long_Label_Name"; &amp;Fld2.Label = "Commit_Long_Label_Name"; &amp;Fld3.Label = "Rollback_Long_Label_Name"; &amp;Fld4.Label = "SAMFAIL_Long_Label_Name"; Else &amp;Fld1.Label = "Initialize"; &amp;Fld2.Label = "Commit"; &amp;Fld3.Label = "Rollback"; &amp;Fld4.Label = "SAMFAIL"; End-If;
Even though all of the radio buttons represent the same record field, GetPageField enables you to reference each radio button individually.