People Code




Local object &oWorkApp, &oWorkBook;


&sFilePath = "C:\temp\TEST_FL.xlsx";
&sFileDestPath = "C:\temp\Test.xlsx";

&oWorkApp = CreateObject("COM", "Excel.Application");
&oWorkApp.DisplayAlerts = "False";

ObjectSetProperty(&oWorkApp, "Visible", True);
&oWorkBook = ObjectGetProperty(&oWorkApp, "Workbooks");
&oWorkBook.Open(&sFilePath);
&oWorkSheet = &oWorkApp.Worksheets("Sheet1");
&oWorkSheet.Range("A1:C5").Font.Bold = True;

&oWorkApp.WorkSheets.Add().Name = "Test";
&oWorkSheet = &oWorkApp.Worksheets("Test");

&oWorkSheet.Range("A1:C5").Font.Bold = True;

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

&oWorkApp.ActiveWorkbook.SaveAs(&sFileDestPath);

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


If you want to save the entire peoplecode of your project you can do it through application designer.
Bellow are the steps to save peoplecode to file.

In application designer
1.Go to Edit->Find In option.
2.Enter find character as semicolon(;) and select your project.
3.Check the Save PeopleCode to file option.
4.Click Find button it will ask a file name.
5.Provide the file name and location where you want to save the file.

Then the peoplecode of your project stored into file.


IsUserInRole(rolename1 [, rolename2]. . .)

Returns a Boolean value: True if the current user belongs to one or more of the roles in the user role array, False otherwise.

Example:
    
     &flag=IsUserInRole("Admin");



&queryString = "&SOURCE=R";
            /* generate a url */
            &url = GenerateComponentRelativeURL(%Portal, %Node, MENUNAME.MenuName, MARKET.marketname,COMPONENT.componentname,PAGE.pagename,action);
           
            /* Append parameters */
            &url = &url | &queryString;
           
            ViewURL(&url, False);
Syntax:
  1.   GenerateComponentRelativeURL(PORTAL.portalname, NODE.nodename, MENUNAME.menuname, MARKET.marketname,COMPONENT.componentname, PAGE.pagename, action, [, keylist])
  2.    ViewURL(URL_str | URL.URL_ID [, NewWindow])
  3.    ViewContentURL(URL_str | URL.URL_ID)


Use the ViewContentURL function to launch a new browser window

Use the ViewURL function to launch the default browser

exmple:

&queryString = "&SOURCE=R";
&url=GenerateComponentRelativeURL(%Portal, %Node, MENUNAME.CH_MENU,"GBL",COMPONENT.CH_COMPONENT,PAGE.CH_PAGE,"U");
 &url = &url | &queryString;
           
 ViewURL(&url, False);


IsUserInRole(rolename1 [, rolename2]. . .)

IsUserInRole() function is used to check whether current user has  the role in his profile or not.

This function returns  a Boolean value:
                                       True if the current user belongs to one or more of the roles in the user role array,
                                        False otherwise.
Example:
 local boolean &hasRole;
 &hasRole= IsUserInRole(CH_ROLE_EMPLOYEE);


&hasRole contains true if the currnet user has CH_ROLE_EMPLOYEE in his profile.

We cannot perform INSERT,UPDATE statement's through SQLEXEC( ) in Rowinit PeopleCode event.

Below is the alternative to perform insertion and updation in rowinit .

Creating a stroed procedure, that perform's the insertion or updation.
Execute the procedure using SQLEXEC( ) in rowinit.

Example:

1.Creating the stored procedures in Oracle

CREATE OR REPLACE PROCEDURE CH_SAMPLE_PROCEDURE
AS 
BEGIN
    UPDATE PS_CH_TEST_TBL
            SET  COUNT=100;
    COMMIT;
END CH_SAMPLE_PROCEDURE;

2.Execute the procedure

EXECUTE CH_SAMPLE_PROCEDURE;
Sample code in ROWINIT:

1.Create a sql object,that contains the sql for creating stored procedure.
    SQLEXEC(SQL.CH_TESTPROCEDURE_SQL);
   Here CH_TESTPROCEDURE_SQL contains a sql for creating stored procedure.
2.Execute procedure.
    SQLEXEC("EXECUTE CH_SAMPLE_PROCEDURE");

Note:
1. To create a stored procedure , you need to have permissions in database level.
2. If you want to check whether the stored procedure is created or not use the below sql.
SELECT * FROM ALL_PROCEDURES WHERE OBJECT_NAME='CH_SAMPLE_PROCEDURE'

Gray function:

      Gray( ) is used to make the field unavailable to change in page.

      Syntax:
                 Gray(scrollpath,targetrow,Record.Fieldname);

      Example:
                 Gray(Record.CH_EMPSTATE, &i, CH_EMPSTATE.STATE);

/* Get the field reference into &field variable */

&field = GetRecord(Record.CH_EMPTYPE).GetField(Field.CH_EMPMAIN);

/* Delete all the values from dropdown list */
&field.cleardropdownlist();

/* Add values to the dropdown list */
&field.adddropdownitem(Descr, Value);
   [Value]: It is actual value which is mapped to the dropdown item
   [Descr]: It is actual text which is visible as a dropdown item
Examples:
&field.adddropdownitem("A", "A");
&field.adddropdownitem("B", "B");
&field.adddropdownitem("C", "C");


/*********************** To move file data****************************/
Exec("cmd /c move " | &file1 | " " | &file2, %Exec_Asynchronous %FilePath_Absolute);

/*********************** To copy file data****************************/
Exec("cmd /c copy " | &file1 | " " | &file2, %Exec_Asynchronous %FilePath_Absolute);

/*************************** To delete the file**************************/
Exec("cmd /c del " | &file1, %Exec_Asynchronous %FilePath_Absolute);

*****************************OR*************************************  
/**************** Create java objects corresponds to files *******************/                           
Local JavaObject &f = CreateJavaObject("java.io.File", "/the/path/to/the/file.txt"); 
Local JavaObject &target = CreateJavaObject("java.io.File", "/the/target/file.txt"); 

&f.renameTo(&target); 

Local JavaObject &f = CreateJavaObject("java.io.File", "/the/path/to/the/file"); 

&f.delete(); /* delete the file from source */



For &i = 1 To &Asmfloor.ActiveRowCount
   &Asmwing = &Asmfloor(&i).GetRowset(Scroll.ASM_WING_TBL);

   For &j = 1 To &Asmwing.ActiveRowCount
      &Asmcabin = &Asmwing(&j).GetRowset(Scroll.ASM_CABIN_TBL);
   
      If &Asmcabin.ActiveRowCount = 1 Then
         &Asmwing.DeleteEnabled = True; /* to enable the row delete option */

         If &Asmwing.ActiveRowCount = 1 Then
            &Asmfloor.DeleteEnabled = True;
         Else
            &Asmfloor.DeleteEnabled = False; /* to disable the row delete option */
         End-If;
         rem &Asmfloor.DeleteEnabled = True;

      Else
         &Asmwing.DeleteEnabled = False;
         &Asmfloor.DeleteEnabled = False;
     
      End-If;
   
   End-For; /* end-of wing */
           
End-For; /* end-of floor */

Local string &File_path, &File_path1;
&File_path = "C:\temp\ascii.xml";
&bud_rep = GetFile(&File_path, "r", %FilePath_Absolute);
&File_path1 = "C:\temp\ascii_1.txt";
&bud_rep1 = GetFile(&File_path1, "a", %FilePath_Absolute);
&count = 0;

While &bud_rep.readline(&line)
   &line1 = Len(&line);
   &count = &count + 1;

   For &i = 1 To &line1
      &char = Substring(&line, &i, 1);
      &naciichar = Code(&char); /* returns the number corresponds to character */
      /* check whether the character is in the range of ascii char's or not */
      If &naciichar >= 128 Or
            &naciichar < 0 Then
         &bud_rep1.writeline(&count | " " | &char); /* write special character to file */
      End-If;

   End-For;

End-While;