Tuesday 19 December 2023

Peoplecode to get primitive , collection ,compound

 








Below is the Peoplecode to get the response message 



Local Message &Request_MSG = CreateMessage(Operation.X_ATTENDANCE_REQUEST_POST, %IntBroker_Request);

Local Message &Response_MSG = CreateMessage(Operation.X_ATTENDANCE_REQUEST_POST, %IntBroker_Response);

Local Message &MSG;

Local boolean &ret;

Local Document &reqDocument, &respDocument;

/*------------------------------------------*/


Local Collection &dataCollection, &dataCollection1;

Local Compound &dataCompound, &respCompound, &respCompound1, &userCompound;


/*-------------------------------------------*/


&Request_MSG.IBInfo.ConnectorOverride = True;



&Request_MSG.URIResourceIndex = 1;

&docMsg = &Request_MSG.GetDocument();

&msg_comp_tmpl = &docMsg.DocumentElement;



&msg_comp_tmpl.GetPropertyByName("accountId").value = X_ATTENDANCE_T0.X_ACCOUNT_ID.Value;

&msg_comp_tmpl.GetPropertyByName("dateFrom").value = DateTimeValue(X_ATTENDANCE_T0.RQSTDTTM.Value);

&msg_comp_tmpl.GetPropertyByName("dateTo").value = DateTimeValue(X_ATTENDANCE_T0.RUNDTTM.Value);



X_ATTENDANCE_T0.DESCRLONG.Value = "";

Local Message &mResp = %IntBroker.SyncRequest(&Request_MSG);

Local array of string &KeyValuePairs = CreateArrayRept("", 0);

Local JsonArray &DataArray, &userArray;

Local JsonObject &userObj, &accessGateObj;

Local integer &transactionTypeID, &resultStatus;

Local datetime &createDate;

Local Rowset &Datagrid_rs;





If &mResp.ResponseStatus = 0 Then

   &content = &mResp.GetContentString();

   &parser = CreateJsonParser();

   &ret = &parser.parse(&content);

   Local JsonObject &jsonRoot = &parser.GetRootObject();

   

   

   For &i = 1 To &jsonRoot.GetChildCount();

      

      &propertyName = &jsonRoot.GetPropertyNameAt(&i);

      

      Local string &propName = &jsonRoot.GetPropertyNameAt(&i);

      Local any &propValue = &jsonRoot.GetProperty(&propName);

      

      

      

      Evaluate &propertyName

      When = "status";

         &status = &jsonRoot.GetProperty(&propertyName) ;

      When = "message";

         &message = &jsonRoot.GetProperty(&propertyName);

      When = "data";

         

         &DataArray = &jsonRoot.GetProperty(&propertyName);

         For &i = 1 To &DataArray.Size;

            Local JsonObject &jsObj = &DataArray.GetJsonObject(&i);

            

            

            /* if a user property exist */

            If &jsObj.IsExist("user") And

                  Not &jsObj.IsNullProperty("user") Then

               

               &userObj = &jsObj.GetJsonObject("user");

               &firstName = &userObj.GetProperty("firstName");

               &lastName = &userObj.GetProperty("lastName");

               &userName = &userObj.GetProperty("userName");

               &jobNumber = &userObj.GetProperty("jobNumber");

               

               rem  MessageBox(0, "", 0, 0, "&firstName -" | &firstName | " &lastName - " | &lastName);

               

            End-If;

            /* if a accessGate property exist */

            If &jsObj.IsExist("accessGate") And

                  Not &jsObj.IsNullProperty("accessGate") Then

               

               &accessGateObj = &jsObj.GetJsonObject("accessGate");

               &nameAr = &accessGateObj.GetProperty("nameAr");

               &nameEn = &accessGateObj.GetProperty("nameEn");

               &beaconId = &accessGateObj.GetProperty("beaconId");

               

               rem MessageBox(0, "", 0, 0, "accessGate");

            End-If;

            If &jsObj.IsExist("transactionTypeID") And

                  Not &jsObj.IsNullProperty("transactionTypeID") Then

               

               &transactionTypeID = &jsObj.GetProperty("transactionTypeID");

               

            End-If;

            

            If &jsObj.IsExist("createDate") And

                  Not &jsObj.IsNullProperty("createDate") Then

               

               &createDate = &jsObj.GetProperty("createDate");

               

            End-If;

            If &jsObj.IsExist("resultStatus") And

                  Not &jsObj.IsNullProperty("resultStatus") Then

               

               &resultStatus = &jsObj.GetProperty("resultStatus");

               

            End-If;

            If &jsObj.IsExist("localTimeZone") And

                  Not &jsObj.IsNullProperty("localTimeZone") Then

               

               &localTimeZone = &jsObj.GetProperty("localTimeZone");

               

            End-If;

            If &jsObj.IsExist("departmentName") And

                  Not &jsObj.IsNullProperty("departmentName") Then

               

               &departmentName = &jsObj.GetProperty("departmentName");

                 End-If;

               End-For;

           End-Evaluate;

         End-For;

End-If;




Sunday 10 December 2023

PeopleSoft REST GET Web Service

Representational State Transfer (REST) is a style of doing Web services that is becoming increasingly popular among web developers because of its simplicity over SOAP and other methods.

1. Build the Template Document 

Documents represent a hierarchical data structure like a Rowset object.  They have a logical and physical representation in XML, HTML and JSON . A document object that will capture all the parameters that may be sent inbound to your web service. 

In this simple example, we will only have one parameter. 







now build a message object based on the document template we built above.

PeopleTools > Integration Broker > Integration Setup > Messages


2. Build the Document & Message for Response


3. Create a REST Service 




3. Create a Service Operation



3. Create  a Service Operation Handler







import PS_PT:Integration:IRequestHandler;

Class GET_STD_DATA implements PS_PT:Integration:IRequestHandler

   method OnRequest(&msgRequest As Message) Returns Message;

   method OnError(&pRequestMsg As Message) Returns string;

  end-class;

method OnRequest

   /+ &msgRequest as Message +/

   /+ Returns Message +/

   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/

   

   Local Message &response, &request;

   Local string &parm1, &parm2, &SecurityKey, &StdID, &L_OPERPSWDSALT1, &FindHash;

   Local string &OEMPLID, &ONAME_DISPLAY, &OSEX, &OCAMPUS_ID, &OACAD_CAREER, &OACAD_PROG, &OPROG_STATUS, &OPROG_REASON, &OADMIT_TERM, &OEXP_GRAD_TERM, &OACAD_PLAN, &ODegree, &OMajor, &OACAD_YEAR, &OYRDESCR, &ODESCRSHORT, &OEFFDT;

   Local string &resultSalt = "123";

   Local string &resultSalt1 = "456";

   Local string &resultSalt2 = "789";

   Local Compound &com;

   &response = CreateMessage(@("Operation." | &msgRequest.OperationName), %IntBroker_Response);

   

   Local Document &reqDOC, &respDOC;

   

   /*---------------------- Request Message -------------------------*/

   

   &reqDOC = &msgRequest.GetURIDocument();

   &com = &reqDOC.DocumentElement;

   &SecurityKey = &com.GetPropertyByName("MYID").value;

   

   /*--------------- Response Message ------------------------------*/

   SQLExec(SQL.L_GET_ID_FROM_TRANSTEXT, &SecurityKey, &StdID);

   SQLExec("select L_OPERPSWDSALT1 from  PS_L_TRNS_PWD1 where OPERPSWDSALT =:1", HashWithSalt(&SecurityKey, &resultSalt), &L_OPERPSWDSALT1);

   SQLExec("select 'Y' FROM  PS_L_TRNS_PWD2 WHERE L_OPERPSWDSALT2 =:1", HashWithSalt(HashWithSalt(&SecurityKey, &resultSalt) | &L_OPERPSWDSALT1, &resultSalt2), &FindHash);

     

   If Not None(&StdID) And

         (&FindHash = "Y") Then

      SQLExec(SQL.L_STD_ACADEMIC_DTL_SQL, &StdID, &OEMPLID, &ONAME_DISPLAY, &OSEX, &OCAMPUS_ID, &OACAD_CAREER, &OACAD_PROG, &OPROG_STATUS, &OPROG_REASON, &OADMIT_TERM, &OEXP_GRAD_TERM, &OACAD_PLAN, &ODegree, &OMajor, &OACAD_YEAR, &OYRDESCR, &ODESCRSHORT, &OEFFDT);

    

   End-If;

   &respDOC = &response.GetDocument();

   &respDOC.GetElement("EMPLID").VALUE = &OEMPLID;

   &respDOC.GetElement("CAMPUS_ID").VALUE = &OCAMPUS_ID;

   &respDOC.GetElement("DISPLAY_NAME").VALUE = &ONAME_DISPLAY;

   &respDOC.GetElement("ACAD_PLAN").VALUE = &OACAD_PLAN;

   &respDOC.GetElement("PLAN_DESCR").VALUE = &OMajor;

   &respDOC.GetElement("ACAD_PROG").VALUE = &OACAD_PROG;

   &respDOC.GetElement("PROG_DESCR").VALUE = &ODegree;

   &respDOC.GetElement("YEAR_ADMITTED").VALUE = &OYRDESCR;

   &respDOC.GetElement("YEAR_GRADUATED").VALUE = &ODESCRSHORT;

   &respDOC.GetElement("ACAD_CAREER").VALUE = &OACAD_CAREER;

   &respDOC.GetElement("PROG_STATUS").VALUE = &OPROG_STATUS;

   &respDOC.GetElement("PROG_REASON").VALUE = &OPROG_REASON;

   &respDOC.GetElement("ADMIT_TERM").VALUE = &OADMIT_TERM;

   &respDOC.GetElement("EXP_GRAD_TERM").VALUE = &OEXP_GRAD_TERM;

   &respDOC.GetElement("SEX").VALUE = &OSEX;

      Return &response;

   end-method;

method OnError

   /+ &pRequestMsg as Message +/

   /+ Returns String +/

   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnError +/

   Return "Error Occured";

end-method;


Check it Using POSTMAN



Wednesday 6 December 2023

PeopleCode to Generate Alpha Numeric Random String

 

Function GenerateUniqueKey() Returns string

   Local string &characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

   Local string &key = "";

   Local number &length = 12; /* Adjust the desired length of the key */

   

   For &i = 1 To &length

         

      &randomCharacter = Substring(&characters, Int(Rand() * 62), 1);

      If (&i = 5 Or

            &i = 9) Then

         &key = &key | "-";

      End-If;

      

      &key = &key | &randomCharacter;

      

   End-For;

   

   Return &key;

End-Function;


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();