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

Tuesday, December 17, 2013

Interview Question: FieldEdit vs FieldChange

FieldEdit and FieldChange are two events that are triggered when a user changes the contents and leave a field on the page.

So why do we need two events after the field content is modified?

We know that FieldEdit is usually used to perform validations  other than standard system edits (such as Required, data type etc) and FieldChange is used to recalculate page field values.

What happens if I use FieldEdit to recalculate the page field values or FieldChange for validations?

In order to understand the reason for why there are two events, we need to understand how the component processor handles field modification.

When a user modifies the field value and tab out (or leave the field), following processing happens in sequential order.

  • Standard system edits are performed .
  • If there are no system edit errors, FieldEdit event is triggered.
  • If there are no errors triggered from FieldEdit peoplecode, modification to the field value is accepted by the component processor and is updated to component buffer.
  • FieldChange event is triggered.
Note that during FieldEdit, content of the field is not accepted by the component processor yet. It is only after successful completion of the FieldEdit without any error message, the content of the field updated to component buffer. This is exactly why we are using FieldEdit for validation.

During FieldChange, field value is already accepted by component processor and is updated to component buffer, hence it make sense to recalculate any other dependent field values in FieldChange peoplecode.

I hope the difference is clear, now please answer my questions. :)

What happens if I use FieldEdit to recalculate the page field values or FieldChange for validations?


Tuesday, December 3, 2013

Interview Question: MessageBox in FieldEdit

For last few weeks I have been busy doing quite a lot of interviews for recruiting new members for my team. One of the common question I used to ask during the interview is this.

Question: I have a field on a page and there is a Field Edit PeopleCode associated with this record field. PeopleCode contains only one statement

MessageBox(0,"",0,0,"Message from FieldEdit");
However when the user changes the field value on the page, this message box is not displayed. What could be the reason? 

 I was surprised to hear different wrong answers. Few of those funny answers are listed below.
  • One of the junior consultant with around 3 years of experience in PeopleSoft told me that FieldEdit would be triggered only if the field is required. (I guess he derived it from the fact that FieldEdit is triggered after the system edits are validated)
  • One of them (with 5 years of experience) answered that there should be some code in FieldChange otherwise FieldEdit wouldn't be executed.
  •  Another gentleman said he is not sure about the reason but he would try to do PeopleCode trace and find out what the issue is.
So what is your answer? Isn't it obvious? :wink

Tuesday, July 2, 2013

Shortcut for Record Field name

Since there is no code completion feature available in PeopleTools App designer (at least as of PT8.53), we need to write the complete record field names when we want to use them in the PeopleCode.

For example if you would want to set the style property of the field, then you would need to write,

JOB.POSITION_NBR.Style = "PSERROR";

If you are writing the piece of code in any events associated with JOB.POSITION_NBR field, then you can write ^ (caret) instead of the record field name. Upon saving the PeopleCode, ^ (caret) will be converted to the record field name.


^.Style = "PSERROR";

Thursday, May 23, 2013

RowDelete Processing Stops mysteriously

Last week I was investigating along with my colleague on an issue in Position Information in Job Data Component, we came across a strange scenario.

In order to fix the issue we had added a piece of code in RowDelete event in one of the fields of JOB  record (Lets call it FIELDXYZ in the rest of this post). Interestingly our code was not triggered even if the rows are deleted from the scroll.

Newly added code in JOB.FIELDXYZ.RowDelete looks like this.

 
If Condition1 And Condition2 And Condition3 Then
    Do THIS;
End-if;

Initially we thought some of the conditions in the "IF" construct are not met and that is why our code was not triggered. As a next step we issued a MessageBox/Winmessage at the beginning of the code (outside IF) to confirm if the RowDelete event itself is executed or not. Result of that trial confirmed that the RowDelete event for the Field was never executed.

So what went wrong? We continued our analysis, went one step ahead and added a MessageBox/Winmessage in the RowDelete event of the field just above the FIELDXYZ. Again this code was also not executed.

Next time MessageBox/Winmessage statement was added to the last RowDelete code(Lets call it FIELDLAST RowDelete code) before FIELDXYZ. This time the code was executed and the MessageBox was popped up.

On analyzing the existing code in the last RowDelete event, we found that the issue happenes when a warning was triggered in RowDelete event. If a warning is issued RowDelete processing stops  no matter what button (OK or Cancel) the user clicks.

We haven't yet uncovered if this is PeopleTools bug or desired functionality. I will update you guys once I have a confirmation.

Thursday, March 7, 2013

Deleting files in a folder using PeopleCode

Almost everyday I spent some time to go through the posts in various PeopleSoft forums like ITToolbox. This helps me to learn new things, I can help others and get help when needed.

Similar to my previous post, this is also related to a question asked on this forum.

Question: How to delete a file through peoplecode through AE process?

Answer: Here is the PeopleCode which will do this.

 Local array of string &fNames;  
 Local file &myFile;  
 Local String &dir;  
 &dir = 'F:\Temp\' | %DbName | '\Email\UTI0XX\*';  
 &fNames = FindFiles(&dir, %Filepath_Absolute);  
 While &fNames.Len > 0  
 For &i=1 to &fNames.Len  
 &myFile = GetFile(&fNames.[&i], "w", %Filepath_Absolute);  
 &myFile.Delete();  
 End-For;  
 End-while;  

PeopleCode as Plain Text

Until recently I didn't realize that there is a table storing PeopleCode as plain text in recent PeopleTools versions. Table name is  PSPCMTXT. Find In feature of Application Designer has been troublesome when the scope of the search is broader hence this new table would make the life of developer much easier when searching for text in PeopleCode. I guess this was introduced from PT 8.5 onwards.

One point to note is that when the PeopleCode text is large in size, it is divided into multiple chunks and stored as multiple rows of data in this table.

Tuesday, March 5, 2013

How to check if a file is editable in PeopleCode

How do we check if a file is editable in PeopleCode? This was a question asked in ITToolbox forum.

We can do this easily using Java File class object.



 &myFileToCheck = "C:\Temp\MYFILE.TXT";  
 Local JavaObject &file = CreateJavaObject("java.io.File", &myFileToCheck);  
 If &file.canWrite() Then  
   /*Normal processing*/  
   MessageBox(%MsgStyle_OK, "", 0, 0, "File is editable!!");  
 Else  
   /*Error processing*/  
   MessageBox(%MsgStyle_OK, "", 0, 0, "File is Read Only!!");  
 End-If;  

Saturday, March 22, 2008

Bypass Component Search Page

We can bypass the component search page in different ways.
1. One way is to set the key values using peoplecode and use the peoplecode function SetSearchDialogBehavior. You can write the code in the SearchInit PeopleCode. Suppose Employee Id is the only key, then the code will look like,


EMPLID = %EmployeeId;
SetSearchDialogBehavior(0);


2. Another way is to use a record which contain only one single row in it eg: PSINSTALLATION.
3. There is another method of using a record with no keys as the component search record. This will also bypass the search.

Based on the requirement you can use any of the above methods.