Tuesday, 20 January 2015

Execute shell commands using Java Runtime in PeopleCode

Java Runtime class can be used to execute shell commands in PeopleCode and capture the output. The example below executes UNIX grep command to count the number of non-blank rows in a file and store the output into a variable.

   Local string &cmd;
   Local number &fileRowCount;
   Local JavaObject &command, &runtime, &process, &inputStreamReader, &bufferedReader;
  
   &cmd = "grep -v ^$ " | &fileName | " | wc -l";
  
   &command = CreateJavaObject("java.lang.String[]", "sh", "-c", &cmd);
   &runtime = GetJavaClass("java.lang.Runtime").getRuntime();
   &process = &runtime.exec(&command);
  
   &inputStreamReader = CreateJavaObject("java.io.InputStreamReader", &process.getInputStream());
   &bufferedReader = CreateJavaObject("java.io.BufferedReader", &inputStreamReader);
   &fileRowCount = &bufferedReader.readLine();

Tuesday, 13 January 2015

PeopleSoft Forms Approval History in PeopleTools 8.52

SQL to review PeopleSoft Forms Approval History in PeopleTools 8.52:

SELECT E.FORM_TYPE,
  A.SEQ_NBR,
  E.FORM_SUBJECT,
  A.EOAWREQUESTOR_ID, -- PERSON WHO SUBMITTED THE WORKFLOW
  C.OPRID,            -- APPROVER
  D.XLATLONGNAME,     -- CURRENT APPROVAL STATUS
  C.DTTM_CREATED,     -- APPROVAL SUBMITTED DATE TIME
  C.EOAWDTTM_MODIFIED -- APPROVAL MODIFIED DATE TIME
FROM SYSADM.PS_FORM_AW A,
  SYSADM.PS_EOAW_STEPINST B,
  SYSADM.PS_EOAW_USERINST C,
  SYSADM.PSXLATITEM D,
  SYSADM.PS_FORM E
WHERE B.EOAWTHREAD_ID = A.EOAWTHREAD_ID
AND B.EOAWPRCS_ID     = A.EOAWPRCS_ID
AND B.EOAWDEFN_ID     = A.EOAWDEFN_ID
AND B.EFFDT           =
  (SELECT MAX(B_ED.EFFDT)
  FROM SYSADM.PS_EOAW_STEPINST B_ED
  WHERE B.EOAWTHREAD_ID   = B_ED.EOAWTHREAD_ID
  AND B.EOAWSTEP_INSTANCE = B_ED.EOAWSTEP_INSTANCE
  AND B.EOAWPRCS_ID       = B_ED.EOAWPRCS_ID
  AND B.EOAWDEFN_ID       = B_ED.EOAWDEFN_ID
  AND B_ED.EFFDT         <= SYSDATE
  )
AND C.EOAWUSTEP_INST_ID =
  (SELECT MAX(C1.EOAWUSTEP_INST_ID)
  FROM SYSADM.PS_EOAW_USERINST C1
  WHERE C1.EOAWSTEP_INSTANCE = B.EOAWSTEP_INSTANCE
  )
AND D.FIELDNAME  = 'EOAWSTEP_STATUS'
AND D.FIELDVALUE = C.EOAWSTEP_STATUS
AND D.EFFDT      =
  (SELECT MAX(D_ED.EFFDT)
  FROM SYSADM.PSXLATITEM D_ED
  WHERE D.FIELDNAME = D_ED.FIELDNAME
  AND D.FIELDVALUE  = D_ED.FIELDVALUE
  AND D_ED.EFFDT   <= SYSDATE
  )
AND D.EFF_STATUS = 'A'
AND E.SEQ_NBR    = A.SEQ_NBR
ORDER BY E.FORM_TYPE, A.SEQ_NBR, B.EOAWTHREAD_ID, B.EOAWSTEP_INSTANCE;