Tuesday, 5 December 2023

Component Interface - Inserting a New Item into a Collection

 Assume you have a collection on the Component Interface and you want to insert a new row into the collection. 

This would be the equivalent of hitting the ‘+’ button on an online page (Scroll area).

To insert a new row to the collection one can use the InserItem method.  one need to specify the index (row number in rowset) while using the method.

&myItem = &Collection.InsertItem(1);


Below is the code for inserting rows in the Transcript Text component in PeopleSoft Campus Solution.


Global File &fileLog;


Global string &FileName;

Global string &PROCESS_INSTANCE;

Global string &RUN_CNTL_ID;


Local ApiObject &oSession, &oLTscrptTextCi;

Local ApiObject &oPersnlFerpaVwCollection, &oPersnlFerpaVw;

Local ApiObject &oSrvcIndSelVwCollection, &oSrvcIndSelVw;

Local ApiObject &oStdntCareerCollection, &oStdntCareer;

Local ApiObject &oTscrptTextLocCollection, &oTscrptTextLoc;

Local ApiObject &oTscrptTextCollection, &oTscrptText;


Function errorHandler()

   Local ApiObject &oPSMessageCollection, &oPSMessage;

   Local number &i;

   Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;

   

   &oPSMessageCollection = &oSession.PSMessages;

   For &i = 1 To &oPSMessageCollection.Count

      &oPSMessage = &oPSMessageCollection.Item(&i);

      &sErrMsgSetNum = &oPSMessage.MessageSetNumber;

      &sErrMsgNum = &oPSMessage.MessageNumber;

      &sErrMsgText = &oPSMessage.Text;

      

   End-For;

   rem ** Delete the Messages from the collection **;

   &oPSMessageCollection.DeleteAll();

End-Function;


&FileName = "DOCKEY_GENERATION_PRCS_LOG" | ".TXT";

&fileLog = GetFile(&FileName, "W");


try

   rem ** Set the Log File **;

   &fileLog = GetFile("C:\Users\MUHAMM~1\AppData\Local\Temp\L_TSCRPT_TEXT_CI.log", "w", "a", %FilePath_Absolute);

   rem &fileLog.WriteLine("Begin");

   rem ** Get current PeopleSoft Session **;

   &oSession = %Session;

   

   rem ** Set the PeopleSoft Session Error Message Mode **;

   rem ** 0 - None **;

   rem ** 1 - PSMessage Collection only (default) **;

   rem ** 2 - Message Box only **;

   rem ** 3 - Both collection and message box **;

   &oSession.PSMessagesMode = 1;

   

   rem ** Get the Component Interface **;

   &oLTscrptTextCi = &oSession.GetCompIntfc(CompIntfc.L_TSCRPT_TEXT_CI);

   If &oLTscrptTextCi = Null Then

      errorHandler();

      throw CreateException(0, 0, "GetCompIntfc failed");

   End-If;

   

   rem ** Set the Component Interface Mode **;

   &oLTscrptTextCi.InteractiveMode = True;

   &oLTscrptTextCi.GetHistoryItems = True;

   &oLTscrptTextCi.EditHistoryItems = True;

   

   rem ** Set Component Interface Get/Create Keys **;

   &oLTscrptTextCi.EMPLID = "20260";

   &oLTscrptTextCi.ACAD_CAREER = "UGDS";

   &oLTscrptTextCi.STDNT_CAR_NBR = 0;

   

   rem ** Execute Get **;

   If Not &oLTscrptTextCi.Get() Then

      rem ** No rows exist for the specified keys.**;

      errorHandler();

      throw CreateException(0, 0, "Get failed");

   End-If;

   

   

   rem ** Begin: Get/Set Component Interface Properties **;

      rem ** Set/Get STDNT_CAREER Collection Field Properties -- Parent: PS_ROOT Collection **;

   &oStdntCareerCollection = &oLTscrptTextCi.STDNT_CAREER;

   Local integer &i126;

   rem For &i126 = 1 To &oStdntCareerCollection.Count;

   rem    &oStdntCareer = &oStdntCareerCollection.Item(&i126);

   &oStdntCareer = &oStdntCareerCollection.Item(1);

   

   rem ** Set TSCRPT_TEXT_LOC Collection Field Properties -- Parent: STDNT_CAREER Collection **;

   &oTscrptTextLocCollection = &oStdntCareer.TSCRPT_TEXT_LOC;

   rem    Local integer &i228;

   rem   For &i228 = 1 To &oTscrptTextLocCollection.Count;

   &oTscrptTextLoc = &oTscrptTextLocCollection.Item(1);

   &oTscrptTextLoc = &oTscrptTextLocCollection.InsertItem(1);

   

   rem &oTscrptTextLoc.PRINT_LOC_SEQ =  [*];

   &oTscrptTextLoc.RELATIVE_POSITION = "K";

   &oTscrptTextLoc.PRINT_LOC = "K";

   &oTscrptTextLoc.INSTITUTION = "LUMS";

   rem &oTscrptTextLoc.STRM = [*];

   rem &oTscrptTextLoc.STDNT_DEGR = [*];

   rem &oTscrptTextLoc.MILESTONE_NBR = [*];

   rem &oTscrptTextLoc.MODEL_NBR = [*];

   rem &oTscrptTextLoc.EXT_ORG_ID = [*];

   rem &oTscrptTextLoc.EXT_DEGREE_NBR = [*];

   

   rem ** Set TSCRPT_TEXT Collection Field Properties -- Parent: TSCRPT_TEXT_LOC Collection **;

   &oTscrptTextCollection = &oTscrptTextLoc.TSCRPT_TEXT;

   rem   Local integer &i339;

   rem    For &i339 = 1 To &oTscrptTextCollection.Count;

   &oTscrptText = &oTscrptTextCollection.Item(1);

   &oTscrptText = &oTscrptTextCollection.InsertItem(1);

   REM &oTscrptText.TEXT_SEQ_NBR =  [*];

   &oTscrptText.TRANSCRIPT_LEVEL = "00"; /* Never Print */

   rem &oTscrptText.TSCRPT_TYPE = [*];

   

   &oTscrptText.SSR_TRANSCRIPT_TXT = "My Transcript Text";

   rem &oTscrptText.TSCRPT_TYPE2 = "OUGDS";

   

   rem      End-For;

   rem   End-For;

   rem  End-For;

   rem ** End: Get/Set Component Interface Properties **;

   

   rem ** Execute Save **;

   

   If Not &oLTscrptTextCi.Save() Then;

      errorHandler();

      throw CreateException(0, 0, "Save failed");

   End-If;

   

   

   rem ** Execute Cancel **;

   rem If Not &oLTscrptTextCi.Cancel() Then;

   rem errorHandler();

   rem throw CreateException(0, 0, "Cancel failed");

   rem End-If;

   

catch Exception &ex


   rem Handle the exception;

   MessageBox(0, "", 0, 0, "" | &ex.ToString());end-try;

rem &fileLog.WriteLine("End");

&fileLog.Close();


Thursday, 14 September 2023

Peoplecode to get HEX values

 

Function hexVal(&iH As integer) Returns string
If &iH <= 9 Then
Return String(&iH);
Else
Return String(Char(Mod(&iH, 9) + 64));
End-If;
End-Function;


Function toHex(&iV As integer) Returns string
Local integer &iH = Mod(&iV, 16);
Local string &sResult = "";

If &iV - &iH = 0 Then
&sResult = hexVal(&iH);
Else
&sResult = toHex(Int((&iV - &iH) / 16)) | hexVal(&iH);
End-If;

Return &sResult;
End-Function;



&sHexValue = hexVal(Code("A"));

Wednesday, 18 January 2023

Instr & Substr functions in RTF

The substr function allows you to extract a substring from a string. The syntax for the substr function is:

substr(string, start_position, length)

string is the source string.

start_position is the position for extraction. The first position in the string is always 1.

length is the number of characters to extract

<?xdofx:substr('128.000',5,1)?>

 output = 0



The instr function returns the location of a substring in a string. The syntax for the instr function is:

instr(string1,string2,[start_position],[nth_appearance])

string1 is the string to search.

string2 is the substring to search for in string1.

start_position is the position in string1 where the search will start. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.

nth appearance is the nth appearance of string2.

<?xdofx:Instr('128.000','.',1)?>

output = 4



Here is an example to use substr and instr function together 

Suppose SSR_TOT_EN_TKNGPA = '128.000'

<?xdofx:substr(SSR_TOT_EN_TKNGPA,Instr(SSR_TOT_EN_TKNGPA,'.',1) + 1,1)?>

output = 0


Saturday, 19 February 2022

Peoplecode to get Long description of Translate Field

 Local Rowset &RsStatus;

&RsStatus = CreateRowset(Record.PSXLATITEM);

&RsStatus.Flush();

&RsStatus.Fill("WHERE FIELDNAME = 'L_COORDINTR_STATUS' AND FIELDVALUE = :1 AND %EFFDTCHECK(PSXLATITEM, FILL, %CURRENTDATEIN) AND EFF_STATUS = 'A'", L_MINOR_APP_FRM.L_COORDINTR_STATUS.Value);



For &l = 1 To &RsStatus.ActiveRowCount

   

   &ValueDescr = &RsStatus(&l).PSXLATITEM.XLATLONGNAME.Value;

   

   

End-For;

Saturday, 29 January 2022

Hide/ Unhide some field on grid/ scroll area

 

If IsUserInRole("CS - Student") Then

   Local Rowset  &rs2;

   

   &rs2 = GetRowset(Scroll.L_MINOR_CRSES);

   

   For &i = 1 To &rs2.ActiveRowCount

      

      rem WinMessage("here");

      &rs2(&i).L_MINOR_APP_WRK.CRSE_GRADE_OFF.Visible = False;

      

   End-For;


End-If;


Tuesday, 11 January 2022

Variables in RTF

 

 

Initialize variable to Y where Found is the name of the variable

<?xdoxslt:set_variable($_XDOCTX, ‘Found’, ‘Y’)?>

 

Print the Variable value 

<?xdoxslt:get_variable($_XDOCTX,’Found’)?>

 

Compare two variables 

<?if:xdoxslt:get_variable($_XDOCTX,’counter’) = xdoxslt:get_variable($_XDOCTX,’tot_lines’)?>


Conditions Matched, You may proceed 

<?end if?>

 

Conditional text using ‘if’ statement

Use “if” statements to customize text in your report. As an example, for the sentence ‘The document is reviewed’, we can add the word ‘not’ depending on the value of a field named STATUS.
Sample: The document is <?if@inlines:STATUS='Overdue'?>not<?end if?> reviewed.
Result: If the STATUS is ‘Overdue’ the text will read ‘The document is not reviewed’. Otherwise, it will read ‘The document is reviewed

We can use the @inlines command to force the template to lay the text out horizontally across the page rather than down the page.

 <ROOT>

<ROW><name>Mike</name> </ROW>

<ROW><name>Max</name></ROW>

<ROW><name>Nick</name></ROW>

</ROOT>

 

<?for-each@inlines:/ROOT/ROW?><?name?> <?end for-each?>

Output : Mike  Max  Nick 

Adding @inlines makes the elements to be displayed without line break.

 ---------------------------------------------------------------------------------------------

?for-each:/ROOT/ROW?><?name?> <?end for-each?>

Output : Mike

         Max  

         Nick 



BI Publisher: Conditional Format

This example will set the row background to red and font

color to white for records where Status is equal to ‘Quote_Received’.

<?if@row:STATUS=’Quote_Received’?>

<?attribute@incontext:background-color;’Red’?>

<?attribute@incontext:color;’White’?>

 <?end if?>



ifelse 

<?xdoxslt:ifelse(condition,true,false)?>

<?xdoxslt:ifelse(A.DESCRSHORT = 'CNG', 'two', 'one')?> 

If Then Else

The following statement tests the AMOUNT element value. If the value is greater than 1000, show the word "Higher"; if it is less than 1000, show the word "Lower"; if it is equal to 1000, show "Equal":

<?xdofx:if AMOUNT > 1000 then 'Higher'

  else

if AMOUNT < 1000 then 'Lower'

   else

   'Equal'

end if?>


<?xdofx:if CB_INV_TRNSTYP='D' then <?xdoxslt:set_variable($_XDOCTX,'DB',CB_INV_AMOUNT)?>

else 

<?xdoxslt:set_variable($_XDOCTX,'DB',0.00)?>endif?>

OR

<?if:CB_INV_TRNSTYP=’D’?><?xdoxslt:set_variable($_XDOCTX,’DB’,CB_INV_AMOUNT)?><?end if?><?if:CB_INV_TRNSTYP!=’D’?><?xdoxslt:set_variable($_XDOCTX,’DB’,0.00)?><?end if?>