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

Thursday, 17 April 2014

Move and Delete files using PeopleCode

Move and Delete files using PeopleCode

We can use the below java object and code to move or deleting files from some location.
Moving file:

Local JavaObject &source = CreateJavaObject("java.io.File", "/source/file.txt");
Local JavaObject &target = CreateJavaObject("java.io.File", "/target/file.txt");

&source.renameTo(&target); 



Deleting file:
Local JavaObject &DelLoc = CreateJavaObject("java.io.File", "/source/file.txt");
&DelLoc.delete(); 
Alternate code for deleting file:
&tmpfile = GetFile(“c:\temp\file.txt”, “W”, “A”, %FilePath_Absolute);
&tmpfile.Delete();

Accessing Application Package class object using CreateObject method.

Let’s say we have 2 application package.
1. UserID and
2. Notification.
Here Notification application package uses dynamic changing application package say based on setup.
For our example we are using UserID application package as setup driven application package and it has UserID as Class.
clip_image002
Structure of UserID application package.
class UserID
   method GetOpridsByApplicationPack() Returns array of string;
   property array of string oprid_arr;
end-class;

method UserID
  
end-method;

method GetOpridsByApplicationPack
   /+ Returns Array of String +/
   
   %This.oprid_arr = CreateArrayRept("", 0);
   Local string &SupervisorId, &ReportsTo;
    
   %This.oprid_arr.push('PS'); /* Logic to populate data in array. */

   Return %This.oprid_arr;

end-method;


Below is “Notification” application package structure. 
In this application package we are using CreateObject to access “GetOpridsByApplicationPack” method of UserID class of UserID application package . 
We are passing Package name and Class Name while calling so they are variable for us. (In this case its UserID and UserID). 
class NotificationManager
method GetOpridsByApplicationPack(&PkgRoot As string, &Appcls_Path As string) Returns array of string;

end-class;

method NotificationManager

end-method;

method GetOpridsByApplicationPack
   /+ &PkgRoot as String, +/
   /+ &Appcls_Path as String +/
   /+ Returns Array of String +/
   Local array of string &aryOpridTo;
   Local string &Classname;
   Local object &u;
   &aryOpridTo = CreateArrayRept(" ", 0);
   &Classname = &PkgRoot | ":" | &Appcls_Path;
   &u = CreateObject(&Classname);
   ObjectDoMethod(&u, "GetOpridsByApplicationPack");
   &aryOpridTo = &u.oprid_arr;
   Return &aryOpridTo;
end-method;

Object–Based PeopleCode

What is Object – Based PeopleCode:
• Introduced in PeopleTools 8
• Evolution of procedural-based PeopleCode
• Provides for complex object definitions
• Overcomes procedural data scope limitations
• Similar to Visual Basic notation
• Interpreted (like VB)
• Not completely object oriented (like C++), but it’s getting there!
• Does not support polymorphisms
• Does support multiple inheritance
• Backwards compatible
Why do we need Object Based PeopleCode:
• Greater ability to write generic code
• Release 8 Integration
                       1. Component Interface
                       2. Application Messaging
                       3. Business Interlinks
• Ability to define custom classes (Release 8.4)
                       1. Application Classes/Packages
                       2. Replaces FUNCLIB Processing
Advantage of Object and Methods:
• Tight code
• Syntax is validated*
• No or low maintenance required
Object – Based PeopleCode Rule:
• DECLARE the object
• INSTANTIATE the object

Object–Based Code to avoid use of SQLEXEC

Below code can be used to avoid use of SQLExec.
SQLExec Code:
SQLExec to copy a row from ORD_HDR to ORD_HDR_EXT.
&ORD_NO = &NEW_ORD_NO;

SQLExec("select %timeout(order_dt), training_loc, vendor_cd, order_status, status_dt, deliver_method from ps_ord_hdr
where order_nbr = :1", &ORD_NO, &ORD_DT, &TRAIN_LOC,&VEND_CD, &ORD_STAT, &STAT_DT, &SHIP_VIA);

SQLExec("delete from ps_ord_hdr_ext where order_nbr = :1", &ORD_NO);

SQLExec("insert into ps_ord_hdr_ext (order_nbr, order_dt,training_loc, vendor_cd, order_status, status_dt,
deliver_method) values(:1,%datein(:2),:3,:4,:5,:6,:7)",&ORD_NO, &ORD_DT, &TRAIN_LOC, &VEND_CD, &ORD_STAT, &STAT_DT,&SHIP_VIA);

Same logic using Object Based code:
Local Record &REC1, &REC2;
&REC1 = GetRecord(RECORD.ORD_HDR);
&REC2 = CreateRecord(RECORD.ORD_HDR_EXT);
&REC1.ORD_NO = &NEW_ORD_NO;
&REC1.SelectByKey();
&REC1.CopyFieldsTo(&REC2);
&REC2.Delete();
&REC2.Insert();

Hiding Delivered Buttons based on condition

One way to hide PeopleSoft delivered component events buttons (Save, ReturnToList, Add, UpdateDisplay…. etc.) by using JavaScript. Follow the below steps to hide the delivered buttons.
This way can be used if we have Many pages in component and we don’t want delivered buttons on some pages. Here are steps.
Step1: Place HTML area in page and assign derived and work record (Say: HIDE_WRK)and field (Say: HTMLAREA) to it.
Create HTML Definition(Say: HIDE_BT_HTML) and Add following JavaScript.
<input type="hidden" name="USERJSINJECTION" value=""/>
<script type="text/javascript">
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
   window.onload = func;
  } else {
   window.onload = function() {
     oldonload();
     func();
   }
  }
}
 
function appsDisablePTControls() { 

var aPTButtons = ['#ICSave', '#ICList', '#ICNextInList', '#ICPrevInList', '#ICSendNotify', '#ICNext', '#ICSpellCheck', '#ICRefresh', '#ICAdd', '#ICUpdateAll', '#ICCorrection', '#ICUpdate']; 

appsDisableTable(aPTButtons,true); 
} 
function appsDisableTable(aPTControls,bButtons) { 

var aControls, oTableNode; 

var bFound = false; 

var i=0; 

while (i < aPTControls.length && !bFound) 

{ 

aControls = document.getElementsByName(aPTControls[i]); 

if (aControls != null && aControls.length > 0) 

{ 

oTableNode = aControls[aControls.length-1].parentNode.parentNode.parentNode.parentNode; 

if (oTableNode != null && oTableNode.id != 'RBTBHEADER' && oTableNode.id != 'RBTBFOOTER') 

{ 

if (bButtons) 

oTableNode = oTableNode.parentNode; 

oTableNode.style.display='none'; 

bFound = true; 

} 

} 

i++; 

} 
} 
addLoadEvent(function() {
  %bind(:1)
});
</script>
Then assign the following code to Page Activated event:
HIDE_WRK.HTMLAREA.Value = GetHTMLText(HTML.HIDE_BT_HTML, "appsDisablePTControls()");
 
Note: Refer the post for how to use Html Area: http://pawan-mundhra.blogspot.com/2011/05/run-javascript-on-your-peoplesoft-pages.html

Run JavaScript on your PeopleSoft pages conditionally

Here, PeopleCode sets the logic that determines when the JavaScript code will run.
This is not as simple as dropping a HTML Area on your page and setting the script in PeopleCode. This is because the value in the HTML Area field remains and the JavaScript code will keep executing at subsequent page refreshes.
Steps:
Lets have a derived/work record TEST_WRK And field HTMLAREA (TEST_WRK – HTMLAREA).
1. Create a HTML definition as your javascript template. Include all the necessary user-defined javascript functions that you need. Eg Html Definition is TESTJS
<input type="hidden" name="USERJSINJECTION" value=""/>
<script type="text/javascript">
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
   window.onload = func;
  } else {
   window.onload = function() {
     oldonload();
     func();
   }
  }
}
 
function user_function1() {
  window.open("","toolbar = no");
}
function user_function2() {
  alert('Hello from user javascript');
}
 
addLoadEvent(function() {
  %bind(:1)
});
</script>
 

2. At the scroll level 0 of your PS page, insert a HTML Area control. Assign this to the TEST_WRK.HTMLAREA field.

3. Again at scroll level 0 of your page, insert an editbox and assign this again to TEST_WRK.HTMLAREA. And Set the Following Field Property


a. On the Use tab, check Invisible and Modifiable by JavaScript.

b. On the General tab, set Page Field Name to USERJSINJECTION.

4. Now in PeopleCode, to execute your javascript function.

GetLevel0()(1).TEST_WRK.HTMLAREA.Value = GetHTMLText(HTML.TESTJS, "user_function1()");
 

Creating MS EXCEL Using CreateObject in PeopleSoft


Here are the few examples how to create EXCEL file and how to read EXCEL file using PeopleCode. This can be used in AppEngine And Online PeopleCode.
This can be used in Excel Reporting and Formatting Excel file (Like changing cell colour etc.… ).
/* Set up the Excel COM objects and open the template file */
Local object &oWorkApp, &oWorkBook;
&oWorkApp = CreateObject("COM", "Excel.Application");
&oWorkApp.DisplayAlerts = "False";
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks");
&oWorkBook.Open("C:\some_path_to\template.xls");
&oWorkSheet = &oWorkApp.Worksheets("Sheet1");
&oWorkApp.ActiveWorkBook.SaveAs("C:\your_output_file.xls");

&oWorkSheet.Cells(1, 1).Value = "I'm adding stuff to be bolded";
&oWorkSheet.Cells(1, 1).Font.Bold = True; 

&oWorkApp.ActiveWorkBook.Save();
&oWorkApp.ActiveWorkBook.Close();
&oWorkApp.DisplayAlerts = "True";
&oWorkApp.Quit();


/*Add data to cells of the first worksheet in the new workbook*/
&oWorkApp = CreateObject("COM", "Excel.Application");
ObjectSetProperty(&oWorkApp, "Visible", True);
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks");
&oWorkBook.add();
&oWorkSheet = &oWorkApp.Worksheets("Sheet1");
&oWorkSheet.Range("A1").Value = "Last Name";
&oWorkSheet.Range("B1").Value = "First Name";
&oWorkSheet.Range("A1:B1").Font.Bold = True;
&oWorkSheet.Range("A2").Value = "Doe";
&oWorkSheet.Range("B2").Value = "John";
&oWorkApp.ActiveWorkbook.SaveAs("E:\Personal\dummy\TestXLS.xls");


/*How to read data from one cell and writes to another*/
&oWorkApp = CreateObject("COM", "Excel.Application"); 
ObjectSetProperty(&oWorkApp, "Visible", True); 
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks"); 
&oWorkBook.Open("E:\Personal\dummy\TEST1.xls"); 
&oWorkSheet = &oWorkApp.Worksheets("Sheet1"); 
&oData = &oWorkSheet.Range("A1").Value; 
&oWorkSheet.Range("A2").Value = &oData;
&oWorkApp.ActiveWorkbook.SaveAs("E:\Personal\dummy\TestXLS.xls");


/*How to read data from one cell and writes to different sheet*/
&oWorkApp = CreateObject("COM", "Excel.Application"); 
ObjectSetProperty(&oWorkApp, "Visible", True); 
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks"); 
&oWorkBook.Open("E:\Personal\dummy\TEST1.xls"); 
&oWorkSheet = &oWorkApp.Worksheets("Sheet1"); 
&oData = &oWorkSheet.Range("A1").Value; 
&oWorkSheet2 = &oWorkApp.Worksheets(2);
&oWorkSheet2.Range("A1").Value = &oData;
&oWorkApp.ActiveWorkbook.SaveAs("E:\Personal\dummy\TestXLS.xls");
/*Add data to cells of the first worksheet in the new workbook*/
&oWorkApp = CreateObject("COM", "Excel.Application"); 
ObjectSetProperty(&oWorkApp, "Visible", True); 
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks"); 
&oWorkBook.Open("E:\Personal\dummy\TEST1.xls"); 
&oWorkSheet = &oWorkApp.Worksheets("Sheet1"); 
&oWorkSheet.Range("A1").Value = "Last Name"; 
&oWorkSheet.Range("B1").Value = "First Name"; 
&oWorkSheet.Range("A1:B1").Font.Bold = True; 
&oWorkSheet.Range("A2").Value = "Doe"; 
&oWorkSheet.Range("B2").Value = "John";
&oWorkApp.ActiveWorkbook.SaveAs("E:\Personal\dummy\TestXLS.xls");
 
/*Transfer the data to Excel from Rowset*/
&oWorkApp = CreateObject("COM", "Excel.Application"); 
ObjectSetProperty(&oWorkApp, "Visible", True); 
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks"); 
&oWorkBook.Open("E:\Personal\dummy\TEST1.xls"); 
&oWorkBook = &oWorkApp.Workbooks.Add(); 
&rs_Awards = CreateRowset(Record.PERTBL); 
&rs_Awards.Fill("WHERE FILL.YEAR = '2008' AND FILL.STATUS = 'C'");
&oWorkSheet = &oWorkApp.Worksheets("Sheet1");
For &ie = 1 To &rs_Awards.activerowcount 
&oWorkSheet.Cells(&ie, 1).Value = &rs_Awards.getrow(&ie).PERTBL.ID.Value; 
&oWorkSheet.Cells(&ie, 2).Value = &rs_Awards.getrow(&ie).PERTBL.COMP.Value; 
End-For;
&oWorkApp.ActiveWorkbook.SaveAs("E:\Personal\dummy\TestXLS.xls");
/*Save an xls file as a CSV*/
&oWorkApp = CreateObject("COM", "Excel.Application"); 
ObjectSetProperty(&oWorkApp, "Visible", True); 
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks"); 
&oWorkBook.Open("E:\Personal\dummy\TEST1.xls"); 
&oWorkApp.ActiveWorkbook.SaveAs("E:\Personal\dummy\TestXLS.csv", 6);

Dynamic Prompt / Edittable Prompt

The following steps help to make Dynamic prompt (Edit Table Prompt).
Lets consider a scenario, based on selection Criteria the Character value prompt need to change.
For Department Character value prompt should be DEPT_TBL and for Job Code the Character value prompt should be JOBCODE_TBL.
image
Now consider the design.
image
The Selection Criteria, Character Value, Process are fields in SQL Record (May change in different case) and Edit Table(EDITTABLE field) is from DERIVED (delivered) derived and work record.
in the above  example your need a record(e.g GR_CRI_TBL) has following fields
SELECTION_TYPE
CHAR_VALUE
PROCESS
CHAR_VALUE should have %EDITTABLE Prompt Table Edit Type
image
Write the following function in any FIELDFORMULA and call the function as given below.
Local string &Type;
Function hide_unhide_popfields(&Row As Row);
   &Type = &Row.GetRecord(Record.GR_CRI_TBL).SELECTION_TYPE.Value;
   Evaluate &Type
   When "D" /* Department */
      &Row.GetRecord(Record.DERIVED).EDITTABLE.Value = Record.DEPT_TBL;
      Break;
   When "J" /* Job Code */
      &Row.GetRecord(Record.DERIVED).EDITTABLE.Value = Record.JOBCODE_TBL;
      Break;
   When "L" /* Location */
      &Row.GetRecord(Record.DERIVED).EDITTABLE.Value = Record.LOCATION_TBL;
      Break;
   End-Evaluate;
End-Function;
Call the above function based on FieldChange and RowInit.
 
Declare Function hide_unhide_popfields PeopleCode GR_CRI_TBL.SELECTION_TYPE FieldFormula;
SetDefault(GR_CRI_TBL.CHAR_VALUE);
hide_unhide_popfields(GetRow());

Changing/Selecting Grid value based on Condition

The following PeopleCode can be used to change the grid value based on condition.
Local Rowset &rsGrid, &rsDataSource;

&rsGrid = GetLevel0().GetRow(1).GetRowset(SCROLL.TEST_VW);
&rsGrid.Flush();

&rsDataSource = CreateRowset(Record.TEST_VW);
&rsDataSource.Flush();
&rsDataSource.Fill(" WHERE EMPLID = :1 AND EMPL_RCD = :2 " &sEmplId,&nEmplRcd);
&rsDataSource.CopyTo(&rsGrid);



The following code can be used to Select grid value based on FieldChange(any condition) event.
&LVL1 = GetLevel0().GetRow(1).GetRowset(Scroll.PER_CHECKLIST);
&LVL2 = &LVL1(CurrentRowNumber()).GetRowset(Scroll.PER_CHKLST_ITM);

If &LVL2.ActiveRowCount = 1 And
      &LVL2(1).IsNew And
      Not &LVL2(1).IsChanged Then
Else
   For &i = &LVL2.ActiveRowCount To 1 Step - 1
      &LVL2.DeleteRow(&i);
   End-For;
End-If;

If All(PER_CHECKLIST.CHECKLIST_CD) Then
   
   &LVL2.SelectNew(Record.CHECKLIST_ITEM, "WHERE CHECKLIST_CD = :1 and EFFDT = (SELECT MAX(A.EFFDT) FROM PS_CHECKLIST_ITEM A WHERE A.CHECKLIST_CD = PS_CHECKLIST_ITEM.CHECKLIST_CD AND A.EFFDT <= %DateIn(:2))", PER_CHECKLIST.CHECKLIST_CD, PER_CHECKLIST.CHECKLIST_DT);
   
End-If;

PSPCMPROG - Table stores PeopleCode of the objects | Explanation

Below information about the table that stores PSPCMPROG the PeopleCode of objects.
PSPCMPROG - 
Key Fields :OBJECTID1, OBJECTID2, OBJECTID3, OBJECTID4, OBJECTID5, OBJECTID6, OBJECTID7 
ObjectID values reference 

1Record
2Field
3Menu
4Bar Name
5Item Name
9Page
10Component
12Event
20Database Type
21Effective Date
39Market
60Message
66Application Engine Program
74Component Interface
77Section
78Step
87Subscription
104Application Package
105Class
106Class
107Class

Key FieldsOBJECTVALUE1, OBJECTVALUE2, OBJECTVALUE3, OBJECTVALUE4, OBJECTVALUE5, OBJECTVALUE6, OBJECTVALUE7 
Refers to object name. 
Key FieldPROGSEQ 
Refers to Program sequence number 
Non Key Fields
VERSION                 Version  
NAMECOUNT           ??  
PROGLEN                 PeopleCode Program Length  
PROGRUNLOC           Program Run Location  
PROGFLAGS             ??  
LICENSE_CODE         License Code  
LASTUPDDTTM         the date and time of the last update to the entry 
LASTUPDOPRID        the OPRID which made the last update to the entry  
PROGEXTENDS         ??  
PROGTXT                 PeopleCode Program

Schedule Application Engine through Peoplecode

The following sample code can be used to Schedule App Engine through PeopleCode.
Code to Schedule App Engine thru PeopleCode:
Local ProcessRequest &MYRQST;
   
   &MyAppName = "MY_APP";
   &MYRQST = CreateProcessRequest("Application Engine", &MyAppName);
   &MYRQST.RunControlID = "TEST";
   &MYRQST.RunLocation = "PSUNX";       
   &MYRQST.Schedule();
   
   If &MYRQST.Status = 0 Then /* if Schedule status is success */
 
  End-If;
Code to know whether the scheduled App Engine ran to success or not:
If &MYRQST.Status = 0 Then /* if Schedule status is success */

      &LOOP = 0;
      While &LOOP = 0
         SQLExec("SELECT A.DISTSTATUS, A.RUNSTATUSDESCR FROM PS_PMN_PRCSLIST A WHERE A.PRCSNAME = :1 AND A.PRCSINSTANCE = (SELECT MAX(B.PRCSINSTANCE) FROM PS_PMN_PRCSLIST B WHERE B.PRCSNAME = A.PRCSNAME)", &MyAppName, &POSTED, &STATUS);
         
         If &STATUS = "Success" And
               &POSTED = 5 Then /* Posted */
            &LOOP = 1
         End-If;
         
         If &STATUS = "Success" And /* Not Posted */
               &POSTED = 4 Then
            &LOOP = 2
         End-If;
         
         If &STATUS = "No Success" Or
               &STATUS = "Error" Then
            &LOOP = 3;
         End-If;
         
      End-While;
      
      If &LOOP = 1 Then
            MessageBox(0, "", 27333, 594, "");  /* Success Msg */
      Else
         If &LOOP = 2 Or
               &LOOP = 3 Then
            MessageBox(0, "", 27333, 595, "");  /* Failed Error Msg */
         End-If;
      End-If; /* If &LOOP = 1 Then */ 
End-If;
 
The below function can also be used for schedule application engine: (Alternative Function)
Function ScheduleSetupAEProcess(&RESULT_SET_COMP)
   &RUN_SETUP_AE_REQST = CreateProcessRequest("Application Engine", "PTLT_SETUP");
   &REC_IMPL_RUN = CreateRecord(Record.PTLT_PROJ_RUN);
   
   /* Run Control ID = Configuration Set Name */
   &RUN_CNTL_ID = &RESULT_SET_COMP;
   
   &RUN_SETUP_AE_REQST.RunControlID = &RUN_CNTL_ID;
   &RUN_SETUP_AE_REQST.Schedule();
   
   If &RUN_SETUP_AE_REQST.Status = 0 Then
      &PROCESS_INSTANCE = &RUN_SETUP_AE_REQST.ProcessInstance;
      /* Insert into Setup Manager Run Control Record */
      &REC_IMPL_RUN.OPRID.Value = %OperatorId;
      &REC_IMPL_RUN.RUN_CNTL_ID.Value = &RUN_CNTL_ID;
      &REC_IMPL_RUN.PTLT_PROJ_NAME.Value = &RESULT_SET_COMP;
      &REC_IMPL_RUN.PROCESSINSTANCE.Value = &PROCESS_INSTANCE;
      
      If Not &REC_IMPL_RUN.Update() Then
         &REC_IMPL_RUN.Insert();
      End-If;
   Else
      Error MsgGet(218, 154, "Process cannot be scheduled");
   End-If;
End-Function;


The following code can be used to schedule App Engine Through PeopleCode.
Local ProcessRequest &MYRQST;
&MyAppName = "TEST_AE";
&MYRQST = CreateProcessRequest("Application Engine", &MyAppName);
&MYRQST.RunControlID = "TEST";
&MYRQST.RunLocation = "PSUNX";
&MYRQST.Schedule();
If &MYRQST.Status = 0 Then /* if Schedule status is success */
End-If;

Functions with EFFDT and EFFSEQ to get row

1. Obtain the row number of Prior Effective date row.  Does not use row with same date and sequence number as itself.
Function prior_effdt_row(&EFFDT, &EFFSEQ, &PRIORDT, &PRIORSEQ, &PRIOR_ROW);
   &ACTIVE_ROW = ActiveRowCount(JOB.EMPLID);
   For &I = 1 To &ACTIVE_ROW;
      &FETCH_EFFDT = FetchValue(JOB.EFFDT, &I);
      &FETCH_EFFSEQ = FetchValue(JOB.EFFSEQ, &I);
      If (&FETCH_EFFDT < &EFFDT Or
            (&FETCH_EFFDT = &EFFDT And
               &FETCH_EFFSEQ < &EFFSEQ)) And
            (&FETCH_EFFDT > &PRIORDT Or
               (&FETCH_EFFDT = &PRIORDT And
                  &FETCH_EFFSEQ > &PRIORSEQ)) Then
         &PRIORDT = &FETCH_EFFDT;
         &PRIORSEQ = &FETCH_EFFSEQ;
         &PRIOR_ROW = &I;
      End-If;
   End-For;
End-Function;

2. Obtain the row number of Prior Effective date row. If it finds row with same effdt and seq row that is not itself, it uses that row.

Function prior_same_effdt(&EFFDT, &EFFSEQ, &CURRENT_ROW, &PRIORDT, &PRIORSEQ, &PRIOR_ROW);
   &ACTIVE_ROW = ActiveRowCount(JOB.EMPLID);
   For &I = 1 To &ACTIVE_ROW;
      &FETCH_EFFDT = FetchValue(JOB.EFFDT, &I);
      &FETCH_EFFSEQ = FetchValue(JOB.EFFSEQ, &I);
      If (&FETCH_EFFDT < &EFFDT Or
            (&FETCH_EFFDT = &EFFDT And
               &FETCH_EFFSEQ <= &EFFSEQ)) And
            (&FETCH_EFFDT > &PRIORDT Or
               (&FETCH_EFFDT = &PRIORDT And
                  &FETCH_EFFSEQ > &PRIORSEQ)) And
            &CURRENT_ROW <> &I Then
         &PRIORDT = &FETCH_EFFDT;
         &PRIORSEQ = &FETCH_EFFSEQ;
         &PRIOR_ROW = &I;
      End-If;
   End-For;
End-Function;


3. Obtain the row number of Next Effective date row

Function next_effdt_row(&EFFDT, &EFFSEQ, &NEXTDT, &NEXTSEQ, &NEXT_ROW);
   &NEXTDT = Date(30001231);
   &NEXTSEQ = 9;
   &ACTIVE_ROW = ActiveRowCount(JOB.EMPLID);
   For &I = 1 To &ACTIVE_ROW;
      &FETCH_EFFDT = FetchValue(JOB.EFFDT, &I);
      &FETCH_EFFSEQ = FetchValue(JOB.EFFSEQ, &I);
      If (&FETCH_EFFDT > &EFFDT Or
            (&FETCH_EFFDT = &EFFDT And
               &FETCH_EFFSEQ > &EFFSEQ)) And
            (&FETCH_EFFDT < &NEXTDT Or
               (&FETCH_EFFDT = &NEXTDT And
                  &FETCH_EFFSEQ < &NEXTSEQ)) Then
         &NEXTDT = &FETCH_EFFDT;
         &NEXTSEQ = &FETCH_EFFSEQ;
         &NEXT_ROW = &I;
      End-If;
   End-For;
End-Function;


4. Obtain the row number of First Effective date row.

Function first_effdt_row(&FIRSTDT, &FIRSTSEQ, &FIRST_ROW);
   &FIRSTDT = Date(30001231);
   &FIRSTSEQ = 9;
   &ACTIVE_ROW = ActiveRowCount(JOB.EMPLID);
   For &I = 1 To &ACTIVE_ROW
      &FETCH_EFFDT = FetchValue(JOB.EFFDT, &I);
      &FETCH_EFFSEQ = FetchValue(JOB.EFFSEQ, &I);
      If (&FETCH_EFFDT < &FIRSTDT Or
            (&FETCH_EFFDT = &FIRSTDT And
               &FETCH_EFFSEQ < &FIRSTSEQ)) Then
         &FIRSTDT = &FETCH_EFFDT;
         &FIRSTSEQ = &FETCH_EFFSEQ;
         &FIRST_ROW = &I;
      End-If;
   End-For;
End-Function;


5. Obtain the row number of row matching date and sequence.


Function det_effdt_row(&EFFDT, &EFFSEQ, &ROW);
   &ACTIVE_ROW = ActiveRowCount(JOB.EMPLID);
   For &I = 1 To &ACTIVE_ROW
      &FETCH_EFFDT = FetchValue(JOB.EFFDT, &I);
      &FETCH_EFFSEQ = FetchValue(JOB.EFFSEQ, &I);
      If &FETCH_EFFDT = &EFFDT And
            &FETCH_EFFSEQ = &EFFSEQ Then
         &ROW = &I;
         &I = &ACTIVE_ROW
      End-If;
   End-For;
End-Function;

Exit(0) And Exit(1) Function in Application Engine.

Exit(0) – Terminates the current PeopleCode Action in application engine.

Exit(1) – Terminates the current Step in application engine.

Sending Multiple attachment using MCF Send mail method.

Below is the sample code to send multiple attachment in mail using MCF Send() mail method.
Local any &FromURL = "record://PV_ATT_DB_SRV/";
Local string &FILENAME;
Local Rowset &rwln1 = CreateRowset(Record.PV_ATTACHMENTS);
Local SQL &Sql1 = CreateSQL("select attachsysfilename from PS_PV_ATTACHMENTS a,ps_SPF_RESUME_ATT b where a.scm_attach_id=b.scm_attach_id  and b.person_id=:1", "000000000000025", &FILENAME);

While &Sql1.Fetch(&FILENAME)
   &attach = create PT_MCF_MAIL:MCFBodyPart();
   Local string &ToFile = "C:/user/" | &FILENAME;
   Local any &errorCode = GetAttachment(&FromURL, &FILENAME, &ToFile);

   If &i = 1 Then
      &multiattach = CreateArray(&attach);
      &multiattach [&i] = &attach;
   Else
      &multiattach [&i] = &attach;
   End-If;
   &multiattach [&i].SetAttachmentContent(&ToFile, %FilePath_Absolute, &FILENAME, " ", "", "");
   &mp.AddBodyPart(&multiattach [&i]);
End-While;
Local PT_MCF_MAIL:MCFBodyPart &test1 = create PT_MCF_MAIL:MCFBodyPart();
Local PT_MCF_MAIL:MCFBodyPart &eMail1 = create PT_MCF_MAIL:MCFBodyPart();

&eMail1.Text = &Message;
&mp.AddBodyPart(&eMail1);
&eMail.MultiPart = &mp;
&res = &eMail.Send();

Local boolean &done;

Evaluate &res
When %ObEmail_Delivered
   /* every thing ok */
   &done = True;
   MessageBox(0, "", 0, 0, "Email Sent Successfully");
   Break;
When %ObEmail_NotDelivered
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Check &email.InvalidAddresses, &email.ValidSentAddresses */
   /*   and &email.ValidUnsentAddresses                        */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   &done = False;
   MessageBox(0, "", 0, 0, "Email Not delivered" | &eMail.InvalidAddresses | &eMail.ValidSentAddresses | &eMail.ValidUnsentAddresses);
   Break;
When %ObEmail_PartiallyDelivered
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Check &email.InvalidAddresses, &email.ValidSentAddresses */
   /*   and &email.ValidUnsentAddresses                        */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   &done = True;
   MessageBox(0, "", 0, 0, "Email Partially delivered" | &eMail.InvalidAddresses | &eMail.ValidSentAddresses | &eMail.ValidUnsentAddresses);
   Break;
When %ObEmail_FailedBeforeSending
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Get the Message Set Number, message number;              */
   /*   Or just get the formatted messages from                */
   /*   &email.ErrorDescription, email.ErrorDetails;           */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   &done = False;
   MessageBox(0, "", 0, 0, "Email Failed Before Sending" | &eMail.ErrorDescription | &eMail.ErrorDetails);
   Break;
End-Evaluate;

If &done = True Then
   While &Sql1.Fetch(&FILENAME)
      Local string &deleteFile = "C:/user/" | &FILENAME;
      Local JavaObject &f = CreateJavaObject("java.io.File", &deleteFile);
      &f.delete();
  End-While;
End-If;

Rowset FILL Method with JOIN / UNION Keyword

FILL method helps to fill stand alone rowset from database directly.
But sometimes it is required to fill rowset Using JOIN / UNION Keyword.
1. Using JOIN Keyword.
Local Rowset &rs = Createrowset(Record.TL_RPTD_TIME);

&rs.Fill("INNER JOIN PS_TL_RPTD_TIME TM ON TM.EMPLID = FILL.EMPLID WHERE FILL.PUNCH_TYPE = '0' AND FILL.EMPLID = :1", &emplid);



2. Using UNION Keyword.
Local Rowset &rs = Createrowset(Record.PERSON);

&rs.Fill("WHERE 1=0 UNION SELECT EMPLID, %DateOut(BIRTHDATE),BIRTHPLACE,BIRTHCOUNTRY,BIRTHSTATE,%DateOut(DT_OF_DEATH),%DateTimeOut(LAST_CHILD_UPDDTM) FROM PS_PERSON WHERE EMPLID = :1", &emplid);

Wednesday, 16 April 2014

PeopleSoft Permission List Queries



1. Component Permission List Query:
This query identify the permission lists and its description associated with component.
SELECT   menu.menuname, compdfn.pnlgrpname, auth.classid permission_list,
CLASS.classdefndesc permission_desc
FROM psauthitem auth,
psmenudefn menu,
psmenuitem menuitm,
pspnlgroup comp,
pspnlgrpdefn compdfn,
psclassdefn CLASS
WHERE menu.menuname = menuitm.menuname
AND menuitm.pnlgrpname = comp.pnlgrpname
AND compdfn.pnlgrpname = comp.pnlgrpname
AND compdfn.pnlgrpname LIKE UPPER (:component_name)
AND auth.menuname = menu.menuname
AND auth.barname = menuitm.barname
AND auth.baritemname = menuitm.itemname
AND auth.pnlitemname = comp.itemname
AND auth.classid = CLASS.classid
GROUP BY menu.menuname, compdfn.pnlgrpname, auth.classid, CLASS.classdefndesc
ORDER BY menu.menuname, compdfn.pnlgrpname, permission_list;

2. Content Reference accessed by a permission list:

This query identifies Content references accessed by Permission List.
SELECT   a.portal_label AS PORTAL_LINK_NAME, a.portal_objname, a.portal_name, a.portal_reftype
FROM psprsmdefn a, psprsmperm b, psclassdefn c
WHERE a.portal_reftype = 'C'
AND a.portal_cref_usgt = 'TARG'
AND a.portal_name = b.portal_name
AND a.portal_reftype = b.portal_reftype
AND a.portal_objname = b.portal_objname
AND c.classid = b.portal_permname
AND a.portal_uri_seg1 <> ' '
AND a.portal_uri_seg2 <> ' '
AND a.portal_uri_seg3 <> ' '
AND c.classid = :permissionlist
AND a.portal_name = :portalname
ORDER BY portal_label;



FRMT = Frame Template

HPGC = Pagelet

HPGT = Homepage Tab

HTMT = HTML template

LINK = Content Reference Link

3. Page Access By Permission List:

SELECT b.menuname, b.barname, b.baritemname, b.pnlitemname AS pagename,
       c.pageaccessdescr,
       DECODE (b.displayonly, 0, 'No', 1, 'Yes') AS displayonly
  FROM psclassdefn a, psauthitem b, pspgeaccessdesc c
WHERE a.classid = b.classid
   AND a.classid = :1
   AND b.baritemname > ' '
   AND b.authorizedactions = c.authorizedactions;

4. PeopleTools Accessed By a Permission List:
SELECT DISTINCT b.menuname
FROM psclassdefn a, psauthitem b
WHERE a.classid = b.classid
AND (   b.menuname = 'CLIENTPROCESS'
OR b.menuname = 'DATA_MOVER'
OR b.menuname = 'IMPORT_MANAGER'
OR b.menuname = 'APPLICATION_DESIGNER'
OR b.menuname = 'OBJECT_SECURITY'
OR b.menuname = 'QUERY'
)
AND a.classid = :PermissionList;

5. Roles Assigned to a Permission List:
SELECT b.rolename, b.classid AS permission_list
FROM psclassdefn a, psroleclass b
WHERE a.classid = b.classid AND a.classid = :permissionlist;

6. User IDs assigned to a Permission List:
SELECT   c.roleuser AS USER_IDs
FROM psclassdefn a, psroleclass b, psroleuser c
WHERE a.classid = b.classid
AND b.rolename = c.rolename
AND a.classid = :permissionlist
GROUP BY c.roleuser;

Thursday, 12 December 2013

Changing the PeopeleSoft Component Tab name (page naem)

We can do the change in two steps:

Step 1: Create HTML Object (html.TEST_ITEM_LABEL) with below script.

<script type="text/javascript"> 
var tabContainer = document.getElementById("PSTAB"); 
if (tabContainer) 
tabContainer.firstChild.firstChild.firstChild.childNodes[0].firstChild.firstChild.innerHTML = "<font color=black size=2 <b>E-Invoice - %bind(:1)</b></font>"; 
</script>

Step2: Write the below peopelcode in page activate.

TEST_INVOICE_WRK.HTMLAREA.Value = GetHTMLText(HTML.TEST_ITEM_LABEL, VENDOR.NAME1);

Wednesday, 6 November 2013

Query for Tree Security



                                Query for  getting list of  records  from access group and tree 



SELECT R.TREE_NAME, G1.TREE_NODE,G.TREE_NODE,R.TREE_NODE  FROM pstreenode  R,  pstreenode  G      ,(SELECT TREE_NAME,TREE_NODE,TREE_NODE_TYPE FROM pstreenode WHERE TREE_NODE_TYPE = 'G' )
G1
WHERE R.TREE_NODE_TYPE = 'R'
AND G.TREE_NODE_TYPE = 'G'
AND R.PARENT_NODE_NAME = G.TREE_NODE
AND G.tree_name = 'QUERY_TREE_AM'
AND R.TREE_NAME = G.TREE_NAME
AND G.PARENT_NODE_NAME = G1.TREE_NODE (+)
AND G.TREE_NAME = G1.TREE_NAME            (+)

ORDER BY 1,2 ;

Monday, 4 November 2013

PeopleSoft Query to find the objects which are not included in the Project

Below are the SQLs to find the Peoplecode and SQL objects which are  created or modified by you but not included in any of your project.
 
 
--------------------------------------------------
-- Selects Peoplecode not inserted in a project
--------------------------------------------------
SELECT
CASE A.OBJECTID1
when 1 then 'Record Peoplecode'
when 3 then 'Menu Peoplecode'
when 9 then 'Page Peoplecode'
when 10 then 'Component level Peoplecode'
when 60 then 'Message Peoplecode'
when 74 then 'Component Interface Peoplecode'
when 87 then 'Subscription Peoplecode'
END AS  OBJect_Type
,
A.OBJECTVALUE1 || '.' || A.OBJECTVALUE2 || '.' || A.OBJECTVALUE3 || '.' || A.OBJECTVALUE4 || '.' || A.OBJECTVALUE5 || '.' || A.OBJECTVALUE6  || '.' || A.OBJECTVALUE7
AS EXTENDED_OBJ_NAME
FROM PSPCMPROG    A 
 , PSPCMTXT B -- join to pspcmtxt to filter out reverted changes (back to blank)
WHERE  LASTUPDOPRID =
AND  A.OBJECTID1 || A.OBJECTVALUE1 || A.OBJECTID2 ||A.OBJECTVALUE2 || A.OBJECTID3 || A.OBJECTVALUE3 || A.OBJECTID4 || A.OBJECTVALUE4
NOT IN
(
SELECT OBJECTID1 || OBJECTVALUE1 || OBJECTID2 || OBJECTVALUE2 || OBJECTID3 || OBJECTVALUE3 || OBJECTID4 || OBJECTVALUE4
FROM PSPROJECTITEM I, PSPROJECTDEFN   d
WHERE I.PROJECTNAME = D.PROJECTNAME
AND D.LASTUPDOPRID =
and i.objecttype in (8,9,39,40,42,43,44,46,47,48)
)
AND a.objectid1                               = b.objectid1
AND a.objectvalue1                        = b.objectvalue1
AND a.objectid2                               = b.objectid2
AND a.objectvalue2                        = b.objectvalue2            
AND a.objectid3                               = b.objectid3
AND a.objectvalue3                        = b.objectvalue3
AND a.objectid4                               = b.objectid4
AND a.objectvalue4                        = b.objectvalue4
AND a.objectid5                               = b.objectid5
AND a.objectvalue5                        = b.objectvalue5
AND a.objectid6                               = b.objectid6
AND a.objectvalue6                        = b.objectvalue6
AND a.objectid7                               = b.objectid7
AND a.objectvalue7                        = b.objectvalue7
AND  A.OBJECTID1 NOT IN   (66,104)
;    
  
 
 
--------------------------------------------------
-- Selects App Engine Peoplecode not inserted in a project
--------------------------------------------------
SELECT
DISTINCT
'Application Engine Peoplecode',
A.OBJECTVALUE1 || '.' || A.OBJECTVALUE2 || '.' || A.OBJECTVALUE3 || '.' || A.OBJECTVALUE4 || '.' || A.OBJECTVALUE5 || '.' || A.OBJECTVALUE6  || '.' || A.OBJECTVALUE7
FROM PSPCMPROG    A 
WHERE  LASTUPDOPRID =
AND   A.OBJECTID1|| A.OBJECTVALUE1|| A.OBJECTID2||A.OBJECTVALUE2||A.OBJECTVALUE3||A.OBJECTVALUE4||A.OBJECTVALUE5  
 NOT IN
(
SELECT I.OBJECTID1 ||I.OBJECTVALUE1 || I.OBJECTID2 ||REPLACE(I.OBJECTVALUE2,' ','')
 FROM PSPROJECTITEM I, PSPROJECTDEFN   d
WHERE I.PROJECTNAME = D.PROJECTNAME
AND D.LASTUPDOPRID =
and objecttype =43
)
and A.OBJECTID1 = 66
;    
 
--------------------------------------------------
-- Selects App Package Peoplecode not inserted in a project
--------------------------------------------------
SELECT
'Application Package Peoplecode'
, A.OBJECTVALUE1 || '.' || A.OBJECTVALUE2
 FROM PSPCMPROG    A 
WHERE  LASTUPDOPRID =
AND   A.OBJECTID1|| A.OBJECTVALUE1|| A.OBJECTID2||A.OBJECTVALUE2
NOT IN
(
SELECT I.OBJECTID1 ||I.OBJECTVALUE1 || I.OBJECTID2 || I.OBJECTVALUE2
 FROM PSPROJECTITEM I, PSPROJECTDEFN   d
WHERE I.PROJECTNAME = D.PROJECTNAME
AND D.LASTUPDOPRID =
and objecttype =58
)
and A.OBJECTID1 = 104
;    
 
 
 
--------------------------------------------------
-- Selects SQL Objects not inserted in a project
--------------------------------------------------
SELECT 
CASE WHEN SQLTYPE = 0 THEN 'SQL Object '
WHEN SQLTYPE = 1 THEN 'App Engine Step '
WHEN SQLTYPE = 2 THEN 'Record View'
WHEN SQLTYPE = 6 THEN 'Application Engine XSLT'
END AS OBJECTTYPE      ,
SQLID
FROM PSSQLDEFN
WHERE   LASTUPDOPRID =
AND  SQLID
NOT IN
(
SELECT OBJECTVALUE1
FROM PSPROJECTITEM I, PSPROJECTDEFN   d
WHERE I.PROJECTNAME = D.PROJECTNAME
AND D.LASTUPDOPRID =
AND OBJECTTYPE in (30)

);