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;




No comments:

Post a Comment