Saturday, January 29, 2011

Validating with Format Specified in Setup Table. (Example: National ID validation Based On Country)

The below code can be used for validating data with specified Format in Setup Table.

For Example:

In Add Person page (or Modify Person page), National ID validation is based on country and each national id has its own format. So hard coding of format is not possible, it should be generic to convert input data to specified format and validate with the Format specified in setup page.
For National ID validation, National ID Type setup page is used for setting up National ID Type and its format.
Page Navigation: Main Menu> Setup HRMS > Foundation Tables > Personal > National ID Type.



Following  code can be used for Converting input data to specified format and validate with the Format.

Code:

/******************************************************
Function : CheckNID_General
Purpose : Check format of NATIONAL_ID against definition in N_NAT_ID_TYPE
Parameters : &NATIONAL_ID, &NID_TYPE, &COUNTRY
Returns :
******************************************************/
Function CheckNID_General(&NATIONAL_ID, &NID_TYPE, &COUNTRY, &NIDFormat);
Local string &Alpha, &Alpha_xz, &Numeric, &TestChar, &MaskChar;
Local number &iNID, &LengthNID;
Local boolean &IsFormatError;
&Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
&Alpha_xz = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
&Numeric = "1234567890";
&IsFormatError = False;
If All(&NATIONAL_ID) Then
If All(&NIDFormat) Then
&LengthNID = Len(&NIDFormat);
If Len(&NATIONAL_ID) > &LengthNID Then
/* Incorrect Length */
&IsFormatError = True;
End-If;
&K = 0;
For &J = 1 To &LengthNID
&ChkChar = Substring(&NIDFormat, &J, 1);
If &ChkChar = "X" Or
&MaskChar = "Z" Then
&K = &K + 1;
End-If;
End-For;
If &K <> &LengthNID Then
&iNID = 1;
While &iNID <= &LengthNID And
Not &IsFormatError
&TestChar = Substring(&NATIONAL_ID, &iNID, 1);
&MaskChar = Substring(&NIDFormat, &iNID, 1);
Evaluate &MaskChar
When = "X"
When = "Z"
/* Any Alpha or Numeric character is acceptable */
If Find(&TestChar, &Numeric) <> 0 Or
Find(&TestChar, &Alpha_xz) <> 0 Then
&IsFormatError = False;
Else
&IsFormatError = True;
End-If;
Break;
When = "9"
/* Must be Numeric */
If Find(&TestChar, &Numeric) = 0 Then
&IsFormatError = True;
End-If;
Break;
When = "A"
/* Must be Alpha */
If Find(&TestChar, &Alpha) = 0 Then
&IsFormatError = True;
End-If;
Break;
When-Other
/* Special: must be equal to the mask character */
If &TestChar <> &MaskChar Then
&IsFormatError = True;
End-If;
Break;
End-Evaluate;
&iNID = &iNID + 1;
End-While;
End-If;
If &IsFormatError Then
/* "The format of the National ID Type %1 for country %2 has to be %3." */
Error (MsgGet(1000, 490, "Message Not Found", &NID_TYPE, &COUNTRY, &NIDFormat));
End-If;
End-If;
End-If;
End-If;
End-Function;
/**********************************************************************/

/******************************************************
Function : CheckNID
Purpose : Main Check of National ID
Parameters : &NID_VRBL, &NID_TYPE, &COUNTRY
Returns :
******************************************************/
Function Check_NID(&NID_VRBL, &NID_TYPE, &COUNTRY);
&NATIONAL_ID = &NID_VRBL;
/* if the NID entered is shorter than its format, we assume an entry without special chars; thus we insert the special chars prior to checking the NID format */
If All(&NATIONAL_ID) Then
SQLExec("Select NATIONAL_ID_FORMAT from PS_NAT_ID_TBL Where N_COUNTRY=:1 AND N_NATIONALIDTYPE =:2", &COUNTRY, &NID_TYPE, &NATIONAL_ID_FORMAT);
<*
If Not None(&NATIONAL_ID_FORMAT) Then
&LENGTH = Len(&NATIONAL_ID_FORMAT);
If Len(&NATIONAL_ID) <= &LENGTH Then
&NATIONAL_ID = Format_NID(&COUNTRY, &NID_TYPE, &NATIONAL_ID, "OUTOFDB");
End-If;
End-If;
*>
End-If;
/*******************/
/* General Check */
/*******************/
CheckNID_General(&NATIONAL_ID, &NID_TYPE, &COUNTRY, &NATIONAL_ID_FORMAT);
END-FUNCTION;
/**********************************************************************/

Saturday, January 22, 2011

Na payroll

Check out this SlideShare Presentation:

Dynamic Filling Translate/Prompt value

The following peoplecode can be used for dynamic filling of Translate/Prompt value. For Prompt value use prompt table name instead of PSXLATITEM record.

Thursday, January 13, 2011

Adding Month, Date, Year (AddToDate)

AddToDate() Can be used to add Number of Years or Months or Date to Date field.
Example:

Function visa_expiratn_dt

Evaluate VISA_PMT_DATA.DURATION_TYPE
When = "Y"
      VISA_PMT_DATA.EXPIRATN_DT = AddToDate(VISA_PMT_DATA.ENTRY_DT,   
      VISA_PMT_DATA.DURATION_TIME, 0, 0);
Break;
When = "M"
     VISA_PMT_DATA.EXPIRATN_DT = AddToDate(VISA_PMT_DATA.ENTRY_DT, 0,     
     VISA_PMT_DATA.DURATION_TIME, 0);
Break;
When = "D"
     VISA_PMT_DATA.EXPIRATN_DT = AddToDate(VISA_PMT_DATA.ENTRY_DT, 0, 0,   
     VISA_PMT_DATA.DURATION_TIME);
Break;
End-Evaluate
End-Function;

Wednesday, January 5, 2011

Retrive Effective Dated Row

GetCurrEffRow() Methode is used to get the current effective dated row.
Lets consider the following code.
 
/* GetCurrEffRow()*/
Local Rowset &ROWSET;

&nCurrentRowNo = CurrentRowNumber(1);
&Row = GetLevel0()(1).GetRowset(Scroll.MY_TBL)(&nCurrentRowNo);
If %Mode = "U" And
   Row.isnew = False Then
   &ROWSET = GetLevel0()(1).GetRowset(Scroll.MY_TBL)(&nCurrentRowNo).GetRowset(Scroll.MY_DOC_REC);
   &NUMBER = ROWSET.GetCurrEffRow().RowNumber;
   &ROWSET(&NUMBER).FILE_ATTACH_WRK.ATTACHADD.Visible = False;
End-If;
  

LongTranslateValue And ShortTranslateValue

The following code is used to get the Long Translate Value of the translate field.
 
/* LongTranslateValue */
Local Any &VALUE;
Local Field &MYFIELD;

&MYFIELD = GetField();
&VALUE = &MYFIELD.LongTranslateValue;
If ALL(&VALUE) Then
   /* do processing */
End-if;
 
Note: Similarly to get the Short Translate Value we can use ShortTranslateValue property.

Monday, January 3, 2011