Oct 31, 2012

How to consume AR System 8 web services with jQuery

... and a few years later ...
I said farewell to good old Flex and turned to the now hyped JavaScript. Yeah right I would not have thought that would happen a few years back. With the various browsers and their JS engines becoming more mature and FAST with each new release, it's hard to avoid it. Node.js, running on v8 (Chromiums's JS engine), is even doing a great job on the server side with its monothreaded, asynchronous conception. Anyway I thought I would share some tips on consuming a BMC Remedy ITSM 8 Out-of-the-Box SOAP web service with jQuery.

The function "getIncidentsList" is pretty straight forward. Instead of using a jQuery plugin or another library that would provide a SOAP client class that could handle any complex WS structure, I chose to directly send the XML in a SOAP message.
  function getIncidentsList(credentials)
  {
   $.mobile.loading('show');
   var wsURL='/arsys/services/ARService?server=' + credentials.server + '&webService=HPD_IncidentInterface_WS';
   var soapMessage ='\
          \
          \
          ' + credentials.username + '\
          ' + credentials.password + '\
          \
          \
          \
          \
          \'Assignee Login ID\'="' + credentials.username + '" AND \'Status\'<5\
          0\
          50\
          \
          \
       ';
   var jqxhr = $.ajax({
    url: wsURL,
    beforeSend: function( xhr ){
      xhr.setRequestHeader(
      "SOAPAction",
      "POST"
      );
    },
    type: "POST",
    dataType: "xml",
    data: soapMessage,
    success: callSuccess,
    error: callError,
    contentType: "text/xml; charset=\"utf-8\""    
   });
   return false;
  }
  
  function callSuccess(request,status)
  {
   $.mobile.loading('hide');
   $(request).find("ns0\\:getListValues").each(function()
   {
    $("#incidentslist").append('
  • '+$(this).find("ns0\\:Incident_Number").text()+'-'+$(this).find("ns0\\:Priority").text()+'

    '+$(this).find("ns0\\:Summary").text()+'

  • '); }); $.mobile.changePage($("#incidentspage")); } function callError(request,status,error) { $.mobile.loading('hide'); alert("error : " + error); }
    This code works when you serve it in an html file stored on a mid-tier. Simply pass the "credentials" array : username, password, server. Hmmm it tastes like Flex. Why ?
    • because I use jQuery's asynchronous calls features ($.ajax)
    • because both Flex (ActionScript) and JavaScript are dialects of ECMAScript
    The "$.mobile" comes with jQuery Mobile.

    No comments: