PeopleSoft and SOAP - Adding Code to Message OnRequest to Process

We are now ready to use the delivered CreateSOAPDoc() functionality to process the SOAP XML created earlier and do the processing in PSFT.Open the SOAPTSTMSG in application designer, and select the "OnRequest" method to write the code into.

The code with explanation is provided below

Local XmlDoc &request, &response;
Local SOAPDoc &soap_req_object, &soap_res_object;
Local number &Nbr1, &Nbr2, &Nbr3;
Local string &biggest, &smallest, &product, ∑

/* In this step we get the Message XML as a XML DOC object */
&request = GetMessageXmlDoc();

/* We now create a SOAP DOC object */
&soap_req_object = CreateSOAPDoc();

/* Use the XMLDoc property of the SOAPDOC API and assign the incoming SOAP XML to this object */

&soap_req_object.XmlDoc = &request;

/* We are now ready to get the values of number 1, number 2 and number 3
into number variables in PSFT */

&Nbr1 = Value(&soap_req_object.GetParmValue(1));
&Nbr2 = Value(&soap_req_object.GetParmValue(2));
&Nbr3 = Value(&soap_req_object.GetParmValue(3));

/* Find biggest, smallest, product, and sum */

If &Nbr1 >= &Nbr2 Then
   If &Nbr1 >= &Nbr3 Then
      &biggest = String(&Nbr1);
   Else
      &biggest = String(&Nbr3);
   End-If;
Else
   If &Nbr2 >= &Nbr3 Then
      &biggest = String(&Nbr2);
   Else
      &biggest = String(&Nbr3);
   End-If;
End-If;

/* Find smallest */
If &Nbr1 <= &Nbr2 Then
   If &Nbr1 <= &Nbr3 Then
      &smallest = String(&Nbr1);
   Else
      &smallest = String(&Nbr3);
   End-If;
Else
   If &Nbr2 <= &Nbr3 Then
      &smallest = String(&Nbr2);
   Else
      &smallest = String(&Nbr3);
   End-If;
End-If;

/* Find Product */
&product = String(&Nbr1 * &Nbr2 * &Nbr3);

/* Find sum */
&sum = String(&Nbr1 + &Nbr2 + &Nbr3);

/* Assemble the Response */

&response = CreateXmlDoc();
&response = CreateXmlDoc("<?xml version='1.0'?><result/>");
&childNode = &response.DocumentElement.AddElement("biggest");
&textNode = &childNode.AddText(&biggest);
&childNode = &response.DocumentElement.AddElement("sum");
&textNode = &childNode.AddText(&sum);
&childNode = &response.DocumentElement.AddElement("product");
&textNode = &childNode.AddText(&product);
&childNode = &response.DocumentElement.AddElement("smallest");
&textNode = &childNode.AddText(&smallest);
ReturnToServer(&response);

This completes the coding part. We have the message structure, code ready to process the incoming SOAP XML.  Let us do some testing on this to confirm that the result is on the expected lines.

No comments:

Post a Comment