Showing posts with label PeopleCode. Show all posts
Showing posts with label PeopleCode. Show all posts

Friday, November 14, 2014

Derived records and its limitations

"Derived records" are useful PeopleSoft objects, but sometimes there is some confusion about them.

If you try to define a scroll area or grid consisting only of derived record fields, the page will not be valid. These objects must contain at least one "real" database field. Sometimes, though, it is necessary to create a scroll or grid that doesn't relate directly to a table or view. One easy way around this problem is to create a dummy view containing just one field that returns one blank space or other unused value. Put that field into your scroll or grid, mark the scroll/grid as "no auto select," and you can now fill and manipulate the scroll/grid without any complaints from the system. (I have also used a dummy view as a component's search record when I wanted to do all of my data selection in code.). Dynamic views can be used as dummy view with no Sql in its definition. This avoids us from creating any database object.

CallAppEngine Function

Use the CallAppEngine function only in events that allow database updates, because, generally, if you are calling Application Engine, you intend to perform database updates. This category of events includes the following PeopleCode events:

•SavePreChange (Page)
•SavePostChange (Page)
•Workflow
•FieldChange 

CallAppEngine cannot be used in a Application Engine PeopleCode action. If you need to access one Application Engine program from another Application Engine program, use the CallSection action.

SetComponentChanged() Function

The SetComponentChanged() built-in PeopleCode function does not work in Page Activate.
SetComponentChanged();

The SetComponentChanged() built-in function is only applicable after the Page Activate event has run.

After PreBuild, PostBuild, Activate event runs, the changed status will be set to false. so if user made some change during above events, they will be ignored after those events.

Transfer and message

When a Transfer, TransferExact, or RedirectURL function follows a WinMessage or Messagebox that is not a think-time function, the message box dialog pop-up is not be displayed.

When MessageBox or WinMessage functions are called with Style 0, in other words, %MsgStyle_OK, the style shows a single 'OK' button and does not act as a Think-Time function.

Solution - Change the MessageBox style to %MsgStyle_OKCancel

Check if component is changed

If ComponentChanged() Then
   &status = "y"
Else
   &status = "N"
End-If;

Friday, March 28, 2014

SQLEXEC () in RowInit PeopleCode

We cannot perform INSERT,UPDATE statement's through SQLEXEC( ) in Rowinit PeopleCode event.

Below is the alternative to perform insertion and updation in rowinit .

Creating a stroed procedure, that perform's the insertion or updation.
Execute the procedure using SQLEXEC( ) in rowinit.

Example:

1.Creating the stored procedures in Oracle

CREATE OR REPLACE PROCEDURE CH_SAMPLE_PROCEDURE
AS 
BEGIN
    UPDATE PS_CH_TEST_TBL
            SET  COUNT=100;
    COMMIT;
END CH_SAMPLE_PROCEDURE;

2.Execute the procedure
 
EXECUTE CH_SAMPLE_PROCEDURE;

Sample code in ROWINIT:

1.Create a sql object,that contains the sql for creating stored procedure.
    SQLEXEC(SQL.CH_TESTPROCEDURE_SQL);
   Here CH_TESTPROCEDURE_SQL contains a sql for creating stored procedure.
2.Execute procedure.
    SQLEXEC("EXECUTE CH_SAMPLE_PROCEDURE");

Note:
1. To create a stored procedure , you need to have permissions in database level.
2. If you want to check whether the stored procedure is created or not use the below sql.
SELECT * FROM ALL_PROCEDURES WHERE OBJECT_NAME='CH_SAMPLE_PROCEDURE'

Thursday, January 30, 2014

CI - Accessing a PSMessages Collection

Use the PSMessages collection to return all of the messages that occur during the session. The following example finds all the messages listed in the PSMessages collections when the Component Interface Save methods fails. The example assumes that &CI is the Component Interface object reference.

If Not &CI.Save() Then
   /* save didn't complete */
   &COLL = &MYSESSION.PSMessages;
   For &I = 1 to &COLL.Count
      &ERROR = &COLL.Item(&I);
      &TEXT = &ERROR.Text;

      /* do message processing */

   End-For;
&COLL.DeleteAll(); /* Delete all messages in queue */
End-if;

As you evaluate each message, delete it from the PSMessages collection. Or, delete all the messages in the queue at once using DeleteAll.

If there are multiple errors when saving a Component Interface, all errors are logged to the PSMessages collection, not just the first occurrence of an error.

CI - General Considerations

This section discusses general considerations for component interface programs.

WinMessage Unavailable
You cannot use the WinMessage API in a component that will be used to build a component interface. Use the MsgGet() function instead.

Email from a Component Interface
To use a component interface to send email, use the TriggerBusinessEvent PeopleCode event, not SendMail.

Related Display
Related display fields are not available for use in a component interface because they are not held in the buffer context that the component interface uses.

Row Inserts
If row insert functionality has been disabled for a page, you must take care when calling inserts against the corresponding component interface. Any PeopleCode associated with buttons used on the page to add rows will not be invoked by the component interface when an insert is done.

Note.
1. If a component has logic that inserts rows on using the RowInsert event, the component interface
cannot identify the change and locate the rows that were inserted by the application code. Generic interfaces such as Excel to Component Interfaces utility and the WSDLToCI will not function correctly when using this type of dynamic insert.

2. The same field is in different scrolls but they do not have the same value
For example, at scroll 0 you might have the field EFFDT set to 01/01/2009. You want the EFFDT field to get the same value in scroll 1, so you write code to set it from the value in level 0 but it isn't working. If this is the case, check the field name in the component interface, you may find that PeopleSoft has automatically renamed it. For example, it might be EFFDT at level 0 but something like EFFDT_1 in level 1 of the component interface. 

CI - Create a user-defined method

Create a user-defined method
1. Right-click anywhere in the component interface view.
2. Select View PeopleCode from the menu.
3. Write the required PeopleCode functions.
4. Set permissions for the methods that you created.

Exporting User-Defined Methods
If you want a user-defined component interface to be exportable, meaning used by code that instantiates the
component interface, the method PeopleCode definition must include a Doc statement. It is in the form of:
Doc <documentation for method>
where <documentation for method> describes what the method does

Example
Function MyFooBar(int foo) returns boolean
Doc  'test'
if (foo >0) then
return True;
else
return False;
end-if;
end-function; 

Monday, October 28, 2013

Rowset Flush() and Select()

&SELECT_STRING = "WHERE 1 = 1";

if [some condition] then
&SELECT_STRING = &SELECT_STRING | " AND YOUR_FIELD = '" | &Variable | "'";
end-if;
[more conditions/fields as required]

&RS1 = GetLevel0()(1).GetRowset(Scroll.YOUR_RECORD_VW);
&RS1.Flush();
&RS1.Select(Record.YOUR_RECORD_VW, &SELECT_STRING);

Wednesday, October 9, 2013

Messagebox Yes No button

REM - confirmation from user;
&n_Check = WinMessage(MsgGetText(0, 0, "Content can not be changed once saved. Do you want to Continue?"), 4);

If &n_Check <> 6 Then
   /* Cancel save */
   MessageBox(0, " ", 20000, 6, "Your content has not been saved");
End-If;


-------------------

&re = WinMessage(&job_SWHA, 1);

0 gives you 'OK'
1 gives you 'OK' and 'Cancel'
2 gives you 'Abort', 'Retry', and 'Ignore'
3 gives you 'Yes', 'No' and 'Cancel'
4 gives you 'Yes' and 'No'
5 gives you 'Retry' and 'Cancel'

The value of &re gives you which button user has selected. 

Friday, September 13, 2013

PeopleCode Insert/update to a record

If All(&str_var1, &nbr_Num1, &nbr_Num2, &str_Var2, &d_Date1, &b_Exists) Then
   &REC = CreateRecord(Record.MY_RECORD);
   &REC.OPRID.Value = %OperatorId;
   &REC.FIELD1.Value = MY_RECORD.FIELD1.Value;
   &b_Update_Flag = &REC.SelectByKey();

   &REC.OPRID.Value = %OperatorId;
   &REC.FIELD1.Value = BITW_PERSON_DTL.FIELD1.Value;
   &REC.FIELD2.Value = MY_RECORD.FIELD2.Value;
   &REC.DATETIME_STAMP.value = %Datetime;

   If &b_Update_Flag Then
      &REC.Update();
   Else
      &REC.Insert();
   End-If;
End-If;

Monday, September 2, 2013

PeopleCode events: Did you know?

1. The Activate event is valid only for pages that are defined as standard or secondary. This event is not supported for subpages. 

2. SearchInit and SearchSave events will only execute if the Allow Search Events for Prompt Dialogs checkbox is selected for the search key’s record field properties in Application Designer. 

3. FieldChange PeopleCode is often paired with RowInit PeopleCode. In these RowInit/FieldChange pairs, the RowInit PeopleCode checks values in the component and initializes the state or value of page controls accordingly. FieldChange PeopleCode then rechecks the values in the component during page execution and resets the state or value of page controls.

To take a simple example, suppose you have a derived/work field called PRODUCT, the value of which is always the product of page field A and page field B. When the component is initialized, you would use RowInit PeopleCode to initialize PRODUCT equal to A × B when the component starts up or when a new row is inserted. You could then attach FieldChange PeopleCode programs to both A and B which also set PRODUCT equal to A × B. Whenever a user changes the value of either A or B, PRODUCT is recalculated.

4. The FieldFormula event is not currently used. Because FieldFormula PeopleCode initiates in many different contexts and triggers PeopleCode on every field on every row in the component buffer, it can seriously degrade application performance. Use RowInit and FieldChange events rather than FieldFormula.

5. Deleting All Rows from a Scroll Area
When the last row of a scroll area is deleted, a new, dummy row is automatically added. As part of the RowInsert event, RowInit PeopleCode is run on this dummy row. If a field is changed by RowInit (even if it’s left blank), the row is no longer new, and therefore is not reused by any of the ScrollSelect functions or the Select method. In this case, you may want to move your initialization code from the RowInit event to FieldDefault.

6. Do not use Error or Warning statements in RowInit PeopleCode. They cause a runtime error.
Do not put PeopleCode in RowInsert that already exists in RowInit, because a RowInit event always initiates after the RowInsert event, which will cause your code to be run twice.

Tuesday, June 25, 2013

PeopleCode Built-in Encryption Functions

The following functions are provided as built-in functions in PeopleCode for encryption/decryption:
    Encrypt/Decrypt

The syntax for these functions (as provided in PeopleBooks) is:
    Encrypt (KeyString, ClearText) returns CipherText
    Decrypt (KeyString, CipherText) returns ClearText

The Encrypt and Decrypt functions rely on a key string which is used as part of the encryption. Note that the key string can be blank so you can simply issue the commands Encrypt(ClearText) and Decrypt(CipherText).

&strCipherText = encrypt("", rtrim(ltrim(&strClearText)));

Sunday, June 16, 2013

Use transfer function to skip search page while going from one component to another


We will need to write the peoplecode on FieldChange of Hyperlink/Pushbutton. 


PeopleCode fetches the values from source based on which we want to search in the destination component. e.g. var1, var2 and var3 are the values picked from source page. Now create the search record of destination component and pass the appropriate values from source to its key fields. 


Now write the peoplecode at the FieldChange of PushButton/Hyperlink of Source component in following format: 

Local Record &rc = CreateRecord(Record.{destination component search record name or level0 key record of page on which we are going});

&rc.{key/search field1.Value} = &var1;
&rc.{key/search field2.Value} = &var2;

Transfer(False, MenuName.{destination menu name}, BarName.{Bar name component is associated to}, ItemName.{destination component name}, Page.{destination page name}, "{action mode A/U/...}", &rc);


Change the sort order of a prompt


Append the char(9), the string with most char(9) will come first in order.

here is the example of same : 
Field.AddDropDownItem("L", Rept(Char(9), 5) | "Low"); 
Field.AddDropDownItem("M", Rept(Char(9), 4) | "Medium"); 
Field.AddDropDownItem("H", Rept(Char(9), 3) | "High");                                              

Tuesday, June 11, 2013

Disable the Save warning

PeopleTools function SetSaveWarningFilterSetSaveWarningFilter(True) disables the Save Warning while SetSaveWarningFilter(False) enables the Save Warning.

This can also be achieved by setting to False the SetComponentChanged property of the rowset that was causing the issue.

As a general rule, if you know the rowset that is causing the issue then you should set the SetComponentChanged property to False since it makes for easier maintenance. The SetSaveWarningFilter option on the other hand, is more of a generic solution for cases where it’s difficult to find out exactly what is causing the issue.

Friday, May 10, 2013

Check Box Select/Deselect All on Grid


The below function is to be used on a grid with multiple check boxes. Place the code behind a FieldChange event and users will have the option to Select or Deselect grid rows all at once.

Function selectAllRows(&rs As Rowset)
   Local number &i;
   Local Row &row;
   
   For &i = 1 To &rs.ActiveRowCount
      &row = &rs.GetRow(&i);
      /* Make sure we only select visible rows. */
      If &row.Visible = True Then
         &row.Selected = True;
      End-If;
   End-For;
end-function;

/*main line*/
Local Rowset &rs;
&rs = GetLevel0()(1).GetRowset(Scroll.scroll_table);

/*Call Function*/
selectAllRows(&rs);

The same code would work for multiple check boxes "Deselect All", just change the name of the function and line &row.Selected = True; to &row.Selected = False;

Make sure the Multiple Row (Check Box) is checked on the grid properties.

Thursday, May 9, 2013

Custom sort in Grid


Custom sort of the grid can be achieved by using peoplecode. 

Create a Rowset for the grid and use the below code. 
&RowsetName.Sort(Record.Field1, "D", Record.Field2, "A"); 

The grid is sorted by Field1 in Descending and Field2 in Ascending order. 

Friday, April 26, 2013

AE/SQR output files to show up in the Process Monitor/Report Repository


Application Engine Example

In tools 8.4x and beyond, any files opened using the GetFile will actually be automatically transfered to the Report Repository.
Local File &f;
&f = GetFile("summary_log.txt", "w", %FilePath_Relative);
&f.WriteLine("Hello World");
&f.close()
The key thing about this code is the %FilePath_Relative parameter. 

SQR Example

Here is a procedure that you can put in an SQC. A variable named $weboutputdir will be populated with the director where you want to open the file.
begin-procedure get-web-outdir

 if $sqr-platform = 'WINDOWS-NT'
    let $dirSep = '\'
 else
    let $dirSep = '/'
 end-if

begin-select
CDM.PRCSOUTPUTDIR
  let $weboutputdir = rtrim(&CDM.PRCSOUTPUTDIR, ' ')  ||  $dirSep

  FROM PS_CDM_LIST CDM WHERE CDM.PRCSINSTANCE = #prcs_process_instance

end-select
end-procedure