Thursday, 27 November 2014

Send SMS Using Peoplecode


Local String &MobileNumbr = "03434605956" ;

Local String &rand1 , &MSG_ID , &reqStr ;

/* Random Msg ID generation */

   &rand1 = Int(Rand() * 10);
   &rand2 = Int(Rand() * 10);
   &rand3 = Int(Rand() * 10);
   &rand4 = Int(Rand() * 10);
   &rand5 = Int(Rand() * 10);
   &rand6 = Int(Rand() * 10);
   &rand7 = Int(Rand() * 25) + 65;
   &rand8 = Int(Rand() * 25) + 65;
  
   &MSG_ID = &rand1 | &rand2 | &rand3 | &rand7 | &rand4 | &rand5 | &rand6 | &rand8;

   &reqStr = "<?xml version=""1.0"" encoding=""utf-8""?>  <soapenv:Envelope xmlns:soapenv=";
   &reqStr = &reqStr | """http://schemas.xmlsoap.org/soap/envelope/""";
   &reqStr = &reqStr | " xmlns:urn=" | """urn:webService""";
   &reqStr = &reqStr | "> <soapenv:Header>  <wsse:Security soapenv:mustUnderstand=""1"" ";
   &reqStr = &reqStr | "xmlns:wsse=";

   &reqStr = &reqStr | """http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-   secext-1.0.xsd""";

   &reqStr = &reqStr | ">   <wsse:UsernameToken> <wsse:Username>PS</wsse:Username> <wsse:Password Type=";

   &reqStr = &reqStr | """http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText""";

   &reqStr = &reqStr | ">PS</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body><urn:sendSMS><arrayData>  <!--You may enter the following 6 items in any order-->  <mobile>";

   &reqStr = &reqStr | &MOBILE;
   &reqStr = &reqStr | "</mobile> <password>password1234</password> <sender>";
   &reqStr = &reqStr | &SENDER;
   &reqStr = &reqStr | "</sender> <numbers>";
   &reqStr = &reqStr | &MOBILE_PHONE;
   &reqStr = &reqStr | "</numbers> <msg>";
   &reqStr = &reqStr | &BODY;
   &reqStr = &reqStr | "</msg> <msgId>";
   &reqStr = &reqStr | &MSG_ID;
   &reqStr = &reqStr | "</msgId></arrayData> </urn:sendSMS>   </soapenv:Body>
</soapenv:Envelope>";

 &length = Len(&BODY);
  
   If &length <= 156 Then
     
     
      /* (1) Create Request Message from Service Operation */
      &reqMsg = CreateMessage(Operation.SENDSMS10005, %IntBroker_Request);

      /* (2) Create XML Document from Request XML Text String */
      &inXml = CreateXmlDoc(&reqStr);

      /* (3) Set XML Document on Request Message */
      &reqMsg.SetXmlDoc(&inXml);

      /* (4) Invoke SyncRequest for Request Message */
      &respMsg = %IntBroker.SyncRequest(&reqMsg);

      /* (5) Get XML Document from Response Message */
      &outXml = &respMsg.GetXmlDoc();
     
      &userProfile = &outXml.DocumentElement;
      Local number &SMSReturn = &userProfile.GetElementsByTagName("return")[1].NodeValue;


Else
      &toLong = "Message body is too long.";
      MessageBox(0, "", 0, 0, "Message Not Sent." | &toLong);
   End-If;
  
  
  
   If  &SMSReturn = 1 Then
      MessageBox(0, "", 0, 0, "Message Sent.");
     
   Else
      If &SMSReturn <> 1 Then
         &Return = "2";
         MessageBox(0, "", 0, 0, "Message Sending Failed. And Return Code Is = " | &SMSReturn);
      End-If;
   End-If;
  

1 comment:

  1. Hi,

    Please show the setup for this IB Message.
    &reqMsg = CreateMessage(Operation.SENDSMS10005, %IntBroker_Request);

    regards

    ReplyDelete