Sample PeopleCode to Invoke Webservices from Command Push Button

You can invoke webservice from a button fieldchange event also .

using &Request = CreateMessage(Operation.serviceoperation_name, %IntBroker_Request);

Example:-
&msg = CreateMessage(Operation.CONVERSIONRATE);
/* Creating the SOAP Request */
&soapReq = CreateSOAPDoc();
&soapReq.AddHeader();
&soapReq.AddEnvelope(%SOAP_Custom);
&EnvNode = &soapReq.EnvelopeNode;
&EnvNode.AddAttribute("xmlns", "http://www.webserviceX.NET");
&soapReq.AddMethod("ConversionRate", 1);
&soapReq.AddParm("FromCurrency", "USD");
&soapReq.AddParm("ToCurrency", "CAD");
&xmldoc = &soapReq.XmlDoc;
&msg.SetXmlDoc(&soapReq.XmlDoc);
&res = %IntBroker.SyncRequest(&msg);
&Response = &res.GenXMLString();
&myXML = CreateXmlDoc(&Response);
/* Extract the Results; */
&myRet = &myXML.GetElementsByTagName("ConversionRateResult");
/* Show Result */
MessageBox(0, "", 0, 0, "USD to CAD = " | &myRet [1].nodevalue);

--------------------------------------------------------------------------------------------------
/* all are not required ,take the values from wsdl") */
&EnvNode.AddAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
&EnvNode.AddAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
&EnvNode.AddAttribute("xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope");
&EnvNode.AddAttribute("xmlns", "http://www.xignite.com/services");

Sample Data Conversion Code and Technique

Example -1

Local File &MYFILE, &MYFILE1;

Local Record &REC;

Local array of string &ARRAY;

Local string &FILE_DIRECTORY, &FileName, &FileNameErr;

Local integer &COUNT, &I, &nbrSlash, &nbrSlash1, &nbrDoubleQuot, &nbrSpace;

Local string &strDate, &strYear, &strMonth, &strDay, &strTime, &strAMPM, &strDateTime, &strEmplid;;

Local string &strDayYear, &strText, &strText1, &strText2, &strDoubleQuot1, &strDoubleQuot2;

Local string &strFilePath, &strFileName, &strRecName;

 

&strFilePath = Record.PATHNAME.Value;

&strFileName = Record.FILENAME.Value;

&strRecName = RECORDNAME.Value;

&FileName = &strFilePath | "/" | &strFileName;

&FileNameErr = &strFilePath | "/" | "Error.log";

 

&MYFILE = GetFile(&FileName, "R", %FilePath_Absolute);

&MYFILE1 = GetFile(&FileNameErr, "W", %FilePath_Absolute);

rem &REC = CreateRecord(Record.RecordName);

&REC = CreateRecord(@("Record." | &strRecName));

&ARRAY = CreateArrayRept("", 0);

 

&COUNT = 0;

If &MYFILE.IsOpen Then

   While &MYFILE.ReadLine(&STRING);

      If &COUNT <> 0 Then

         rem &ARRAY = Split(&STRING, Char(9));  /**For Tab separated***/

         &ARRAY = Split(&STRING, ",");  /*** for Comma Seperated***/

         For &I = 1 To &REC.FieldCount

            &MYFILE1.WriteLine("RowNum: " | &COUNT | "  " | RTrim(LTrim(&ARRAY [&I])) | " Field Type:" | &REC.GetField(&I).Type | " Field Name:" | &REC.GetField(&I).Name);

            If &REC.GetField(&I).Type = "DATE" Then

               &strDate = (RTrim(LTrim(&ARRAY [&I])));

               &nbrSlash = Find("/", &strDate);

               If &nbrSlash > 0 Then

                  &strMonth = Substring(&strDate, 1, &nbrSlash - 1);

                  If Len(&strMonth) = 1 Then

                     &strMonth = "0" | &strMonth;

                  End-If;

                  &strDayYear = Substring(&strDate, &nbrSlash + 1, Len(&strDate));

                  &nbrSlash1 = Find("/", &strDayYear);

                  &strDay = Substring(&strDayYear, 1, &nbrSlash1 - 1);

                  If Len(&strDay) = 1 Then

                     &strDay = "0" | &strDay;

                  End-If;

                  &strYear = Substring(&strDayYear, &nbrSlash1 + 1, Len(&strDayYear));

                  If Len(LTrim(RTrim(&strYear, " "), " ")) = 2 Then;

                     If Value(&strYear) > 40 Then

                        &strYear = "19" | &strYear

                     Else

                        &strYear = "20" | &strYear

                     End-If;

                  End-If;

                  rem    &MYFILE1.WriteLine("RowNum: " | &COUNT | " &strDate:" | &strDate | "  &strDayYear:" | &strDayYear | " &strMonth:" | &strMonth | " &strDay:" | &strDay | " &strYear:" | &strYear);

                  &REC.GetField(&I).Value = Date3(Value(&strYear), Value(&strMonth), Value(&strDay));

               Else

                  If RTrim(LTrim(&ARRAY [&I])) = "" Then

                     &REC.GetField(&I).Value = Date(0);

                  Else

                     &REC.GetField(&I).Value = Date(RTrim(LTrim(&ARRAY [&I])));

                  End-If;

               End-If;

            Else

               If &REC.GetField(&I).Type = "DATETIME" Then

                  &strDate = (RTrim(LTrim(&ARRAY [&I])));

                  &nbrSlash = Find("/", &strDate);

                  If &nbrSlash > 0 Then

                     &strMonth = Substring(&strDate, 1, &nbrSlash - 1);

                     If Len(&strMonth) = 1 Then

                        &strMonth = "0" | &strMonth;

                     End-If;

                     &strDayYear = Substring(&strDate, &nbrSlash + 1, Len(&strDate));

                     &nbrSlash1 = Find("/", &strDayYear);

                     &strDay = Substring(&strDayYear, 1, &nbrSlash1 - 1);

                     If Len(&strDay) = 1 Then

                        &strDay = "0" | &strDay;

                     End-If;

                     &nbrSpace = Find(" ", LTrim(RTrim(&strDayYear, " "), " "));

                     &strYear = Substring(&strDayYear, &nbrSlash1 + 1, &nbrSpace - 3);

                     If Len(LTrim(RTrim(&strYear, " "), " ")) = 2 Then;

                        If Value(&strYear) > 40 Then

                           &strYear = "19" | &strYear;

                        Else

                           &strYear = "20" | &strYear;

                        End-If;

                     End-If;

                    

                     &strTime = LTrim(RTrim(Substring(&strDayYear, &nbrSpace + 1, Len(&strDayYear)), " "), " ");

                     &strAMPM = Substring(&strTime, 9, 10);

                     &strTime = Substring(&strTime, 1, 8);

                     rem &strDateTime = LTrim(RTrim(&strYear, " "), " ") | "-" | &strMonth | "-" | &strDay | " " | LTrim(RTrim(&strTime, " "), " ");

                     &strDateTime = &strMonth | "/" | &strDay | "/" | &strYear | " " | &strTime | " " | &strAMPM;

                     rem   &MYFILE1.WriteLine("RowNum: " | &COUNT | " &strDate:" | &strDate | "  &strDayYear:" | &strDayYear | " &strMonth:" | &strMonth | " &strDay:" | &strDay | " &strYear:" | &strYear | " &strTime:" | &strTime | " &strAMPM:" | &strAMPM | " &strDateTime:" | &strDateTime);

                     &REC.GetField(&I).Value = DateTimeValue(LTrim(RTrim(&strDateTime, " "), " "));

                  Else

                     &REC.GetField(&I).Value = Date(RTrim(LTrim(&ARRAY [&I])));

                  End-If;

               Else

                  If &REC.GetField(&I).Type = "CHAR" Or

                        &REC.GetField(&I).Type = "LONGCHAR" Then

                     &strText = RTrim(LTrim(&ARRAY [&I]));

                     If LTrim(RTrim(&REC.GetField(&I).Name, " "), " ") = "EMPLID" Then

                        &strEmplid = Rept("0", 9 - Len(&strText)) | &strText;

                        &REC.GetField(&I).Value = &strEmplid;

                     Else

                        If &strText <> "" Then

                           &REC.GetField(&I).Value = &strText;

                        Else

                           &REC.GetField(&I).Value = " ";

                        End-If;

                     End-If;

                  Else

                     If &REC.GetField(&I).Type = "NUMBER" Or

                           &REC.GetField(&I).Type = "SIGNEDNUMBER" Then

                        &strText = RTrim(LTrim(&ARRAY [&I]));

                        If &strText <> "" Then

                           &REC.GetField(&I).Value = Value(&strText);

                        Else

                           &REC.GetField(&I).Value = 0;

                        End-If;

                     End-If;

                  End-If;

               End-If;

            End-If;

         End-For;

         &REC.Insert();

      End-If;

      &COUNT = &COUNT + 1;

   End-While;

Else

End-If; 


PeopleCode to Import data from Multiple files into PS Records


Sample Peoplecode to import data from multiple text(.txt) files into PeopleSoft Records using FindFiles Function as below,

/*PeopleCode to Import Data into Record from Multiple .txt files */

Local File &FILE1;

Local Record &REC1;

Local SQL &SQL1;

Local Rowset &RS1, &RS2;

Local string  &path;

Local array of string &ARRAY;

Local string &STRING;

Local array of string &aFileNames = CreateArrayRept(“”””, 0);

Local File &fSourceFile;

&path = “D:\InboundFiles\*.txt”;

&aFileNames = FindFiles(&path, %FilePath_Absolute);

While &aFileNames.Len > 0

&fSourceFile = GetFile(&aFileNames.Shift(), “R”, %FilePath_Absolute);

&REC = CreateRecord(Record.SY_SYSTEM_INFO);

&ARRAY = CreateArrayRept(“”, 0);

If &fSourceFile.IsOpen Then

If &fSourceFile.SetFileLayout(FileLayout.SY_SYSTEM_INFO_FLO) Then

While &fSourceFile.ReadLine(&STRING);

&ARRAY = Split(&STRING, “;”);

For &I = 1 To &REC.FieldCount

&REC.GetField(&I).Value = &ARRAY [&I];

End-For;

/* do additional processing here for converting values */

&REC.Insert();

End-While;

Else

/* filelayout not correct */

End-If;

Else

/* file not open */

End-If;

&fSourceFile.Close();

End-While;

Zip and Email large file in Application engine PeopleCode

Zip and Email large file:

&qryFile="Vendor_details";

&zip_name="Zip_File_name";

Local string &ZipFile = %FilePath | &zip_name;

Local string &Zip_Cmd = "D:BatchServerBatchPKzip25 " | &ZipFile | " -add " | &qryFile | "." | &ext;

CommitWork();

&ExitCode = Exec(&Zip_Cmd, %Exec_Synchronous + %FilePath_Absolute);

&email.AddAttachment(&ZipFile, %FilePath_Absolute, &zip_name, &attachDescr, "", "");


Using Java code to zip the file:

   &buffer = CreateJavaArray("byte[]", 18024);

    &zipStream = CreateJavaObject("java.util.zip.ZipOutputStream", CreateJavaObject("java.io.FileOutputStream", &outDir | &outZip));

    For &i = 1 To &inFiles.Len

      &zipStream.putNextEntry(CreateJavaObject("java.util.zip.ZipEntry", &inFiles [&i]));

      &inStream = CreateJavaObject("java.io.FileInputStream", &outDir | &inFiles [&i]);

      &len = &inStream.read(&buffer);

      While &len > 0;

        &zipStream.write(&buffer, 0, &len);

        &len = &inStream.read(&buffer);

      End-While;

      &zipStream.closeEntry();

      &inStream.close();

    End-For;

   &zipStream.close();


Here is an IScript that demonstrates this:

Function IScript_GetAttachment()

   Local any &data;

   Local string &file_name = "attachment.doc";   

   Local SQL &cursor = CreateSQL("SELECT FILE_DATA FROM PS_EO_PE_MENU_FILE WHERE ATTACHSYSFILENAME = :1 ORDER BY FILE_SEQ", &file_name);


   REM Set the following header if you want a download prompt. Don't set it if you want inline content;

   %Response.SetHeader("content-disposition", "attachment;filename=" | &file_name);


   While &cursor.Fetch(&data);

      %Response.WriteBinary(&data);

   End-While;

End-Function;



Extracting ZIP files through PeopleCode:

Sometimes we need to extract the ZIP files and then load the extracted file data into PeopleSoft tables using interfaces.

Now, in this scenario will see how to extract the ZIP File using PeopleCode.

Find the below sample code to unzip the ZIP files.


Local string &SourceZipFilePath, &targetPath;


&SourceZipFilePath= “D:\PSOFT\PSREPORTS\FIN92TST\FILES\Expenses.zip”;

&targetPath= “D:\PSOFT\PSREPORTS\FIN92TST\FILES\”;

Local JavaObject &zipFileInput = CreateJavaObject(“java.io.FileInputStream”, &SourceZipFilePath);

Local JavaObject &zipInputStream = CreateJavaObject(“java.util.zip.ZipInputStream”, &zipFileInput);

Local JavaObject &zipEntry = &zipInputStream.getNextEntry();

Local JavaObject &buf = CreateJavaArray(“byte[]”, 1024);

Local number &byteCount;

While &zipEntry <> Null

If (&zipEntry.isDirectory()) Then

/****Nothing to process****/

Else

Local JavaObject &OutputFile = CreateJavaObject(“java.io.File”, &targetPath| &zipEntry.getName());

&OutputFile.getParentFile().mkdirs();

Local JavaObject &out = CreateJavaObject(“java.io.FileOutputStream”, &OutputFile );

&byteCount = &zipInputStream.read(&buf);

While &byteCount > 0

&out.write(&buf, 0, &byteCount);

&byteCount = &zipInputStream.read(&buf);

End-While;


PeopleCode to retrieve Google map between two addresses

  PeopleCode Example: /* Define constants for the API request */ Local string &origin = "123 Main St, Anytown, USA";   /* ...