Tuesday, May 25, 2010

file copy

/*

Developer:    Andrew Casey
Date:         20/05/2010
Reference:    REC20.15
Description:  Created a new class to copy a file to a new location.

*/

/**
* This class has been created to allow move and copy functions, rather than using a java class
* or an Exec() function. 
*
* The class uses the file attachment functions and relies on the FILEDB url to put/get/delete 
* the attachment.
*
* @version 1.0
* @author  Andrew Casey
*/
class copyFile;
   
   method copyFile();
   method copyTheFile(&strCurrFile As string, &strNewFile As string, &blnDeleteFile As boolean, &bnDeleteAttach As boolean);
   
end-class;

/**
  * This is an empty constructor method.
  *
  */
method copyFile
   
end-method;

/**
  * This method will perform the "file copy".
  *
  * @param &strCurrFile    This is the full path and name for the file to be copied.
  * @param &strNewFile     This is the full path and name of the destination, ie. where 
  *                        the file should be copied to.
  * @param &blnDeleteFile  A boolean switch on whether or not the original file should be
  *                        deleted. A True would work like a "move" and a False would work
  *                        like a "copy".
  * @param &bnDeleteAttach A boolean switch on whether or not to remove the file attachment 
  *                        from the database record.
  */
method copyTheFile
   /+ &strCurrFile as String, +/
   /+ &strNewFile as String, +/
   /+ &blnDeleteFile as Boolean, +/
   /+ &bnDeleteAttach as Boolean +/
   
   Local File &flOrigFile;
   
   Local array of string &aryFilePath;
   
   Local integer &intRtrn, &i;
   Local string &strPSHome, &strSeparator, &strCurrFileName;
   Local boolean &blnExists;
   
   rem Derive the separator - used later in the split function;
   &strPSHome = GetEnv("PS_HOME");
   
   rem if the file is on unix then the first character will be a "/";
   If Substring(&strPSHome, 1, 1) = "/" Then;
      &strSeparator = "/";
   Else
      &strSeparator = "\";
   End-If;
   
   rem Now check that the "current" file actually exists;
   If FileExists(&strCurrFile, %FilePath_Absolute) Then;
      
      rem Derive the name of the actual file - for the "current" file;
      &aryFilePath = Split(&strCurrFile, &strSeparator);
      &strCurrFileName = &aryFilePath [&aryFilePath.Len];
      
      rem Add the file to the database;
      &intRtrn = PutAttachment(URL.FILEDB, &strCurrFileName, &strCurrFile);
      If &intRtrn <> %Attachment_Success Then;
         WriteToLog(%ApplicationLogFence_Error, "Add Attachment failed. PutAttachment error: " | String(&intRtrn) | ". File: " | &strCurrFile);
      Else
         rem Adding the attachment did work - now place the attachment where required;
         &intRtrn = GetAttachment(URL.FILEDB, &strCurrFileName, &strNewFile);
         If &intRtrn <> %Attachment_Success Then;
            WriteToLog(%ApplicationLogFence_Error, "Get Attachment failed. GetAttachment error: " | String(&intRtrn) | ". File: " | &strCurrFileName);
         Else
            rem Remove the attachment from the database - if necessary;
            If &bnDeleteAttach Then;
               &intRtrn = DeleteAttachment(URL.FILEDB, &strCurrFileName);
               If &intRtrn <> %Attachment_Success Then;
                  WriteToLog(%ApplicationLogFence_Error, "Delete Attachment failed. DeleteAttachment error: " | String(&intRtrn) | ". File: " | &strCurrFileName);
               End-If;
            End-If;
            rem Remove the original file - if necessary;
            &flOrigFile = GetFile(&strCurrFile, "R", %FilePath_Absolute);
            If &flOrigFile.IsOpen Then;
               &flOrigFile.Delete();
            End-If;
            &flOrigFile.Close();
         End-If;
      End-If;
   Else
      rem File doesn't exist;
      WriteToLog(%ApplicationLogFence, "File does not exist: " | &strCurrFile);
   End-If;
   
end-method;

Friday, April 23, 2010

SOAP Examples

http://thinktibits.blogspot.com/2010/04/peoplesoft-soap-implementation-soapdoc.html

Tuesday, February 16, 2010

XMLP PeopleCode: unzip

/* Unzip the zip file contents using the Peoplesoft XMLPUtil java class.*/
&joUtil = CreateJavaObject("com.peoplesoft.pt.xmlpublisher.XMLPUtil");
&bRet = &joUtil.processZipUtilCommand("-extract " | &sZipFilePath | " " | &sOuptutDirName);
    
    
/*If unsuccesfully unzipped then write errors to file.*/
If Not &bRet Then
   MessageBox(0, "", 0, 0, "The Zip file: " | &DataFileName | " was not extracted successfully.");
   &LogFile.WriteLine("The Zip file: " | &DataFileName | " was not extracted successfully.");
End-If;

Limit characters in a long edit box

< script language="text/javascript" >
   //get the outer html
   if(document.getElementById("YOUR_REC_YOUR_FLD$0")!=null)
   {var outerhtm=document.getElementById("YOUR_REC_YOUR_FLD$0").outerHTML;
    //declare our function call
    var addedText= " onchange=this.focus; onkeyup=this.focus; onblur=parseText(this); "
    // reconstruct the outer htm
    outerhtm=outerhtm.substring(0,outerhtm.indexOf(">"))+addedText+ outerhtm.substring(outerhtm.indexOf(">"),outerhtm.length);
    //assign the reconstructed htm.
   document.getElementById("YOUR_REC_YOUR_FLD$0").outerHTML=outerhtm;
   }
   
   function parseText(textElem)
   {//this function does the length checking for objects defined in the case statements below. 
   switch(textElem.name)
    {
    case "YOUR_REC_YOUR_FLD$0":
     if(textElem.value.length >650 ){alert("Short Description has a maximum length of 650 characters\nIt is currently "+textElem.value.length+" characters.");textElem.style.background="red";textElem.focus();}
     else{textElem.style.background="white";}
    break;
    }
   }
< /script >

Wednesday, January 20, 2010

top-n query

Noted Oracle expert Tom Kyte has written wonderful column on getting first n-rows and n-to-m rows using ROWNUM. ( References: 1,2 )

Check out this link for more info..