Consuming Web Services from SalesLogix VBScript

A really great thread has been evolving in the slxdeveloper.com forums about consuming web services from SalesLogix VBScript plugins. Take a look:

Some highlights of the thread include Jason Huber’s post showing an example using the MS SOAP SDK (^):

I created a little WS at http://www.huberstyle.com/slxws/calc.asmx?wsdl using .net although this isnt important.
I ensured I could view my WSDL by using the above link. My WSDL shows you that I have one function called ADD that accepts two ints and returns an int.

I also needed to install the Soap Toolkit on the client machine:
http://www.microsoft.com/downloads/details.aspx?FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displaylang=en

Dim soapClient3, strResult
Set soapClient3 = CreateObject(“MSSOAP.SoapClient30”)
Call soapClient3.mssoapinit(“http://www.huberstyle.com/slxws/calc.asmx?wsdl”)
strResult = soapClient3.Add(3,4)
msgbox(strResult)

Timmus posted an example demonstrating calling the web service using XMLHTTP, passing some parameters to the web service, and parsing the XML results (^):

This web service accepts four parameters:

    [GetUser xmlns="http://tempuri.org/"]
[FirstName]string[/FirstName]
[LastName]string[/LastName]
[ReportsToFirstName]string[/ReportsToFirstName]
[ReportsToLastName]string[/ReportsToLastName]
[/GetUser]

It then returns a user object that has 3 properties: FirstName (string), LastName (string), ReportsTo(user). This will give us the ability to see how nesting objects will be returned and parsed in the dom.

Here is the code calling the web service:

option explicit
dim oXMLDoc
dim oXMLHTTP

Sub Button1Click(Sender)
set oXMLDoc = CreateObject("Msxml2.DOMDocument")
set oXMLHTTP = CreateObject("Msxml2.XMLHTTP.3.0")

oXMLHTTP.onreadystatechange = getRef("HandleStateChange")
call oXMLHTTP.open("POST", "http://localhost:3163/GetCurrentTime/Service.asmx/GetUser", false)
call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
call oXMLHTTP.send("FirstName=Bill&LastName=Clinton&ReportsToFirstName=Hillary&ReportsToLastName=Clinton")


end sub

sub HandleStateChange
dim sFirstName
dim sLastName
dim sReportsToFN
dim sReportsToLN

if (oXMLHTTP.readyState = 4) then
dim szResponse: szResponse = oXMLHTTP.responseText

call oXMLDoc.loadXML(szResponse)
if (oXMLDoc.parseError.errorCode <> 0) then
call msgbox (oXMLDoc.parseError.reason)
else
sFirstName = oXMLDoc.getElementsByTagName("User")(0).childNodes(0).text
sLastName = oXMLDoc.getElementsByTagName("User")(0).childNodes(1).text
sReportsToFN = oXMLDoc.getElementsByTagName("User")(0).childNodes(2).childNodes(0).text
sReportsToLN = oXMLDoc.getElementsByTagName("User")(0).childNodes(2).childNodes(1).text

call msgbox(sFirstName & " " & sLastName & " reports to " & sReportsToFN & " " & sReportsToLN)

end if
end if
End Sub

As you can see the XMLDom is quite simple to traverse although I find it critical to have a good debugger so you can visually traverse the DOM. Once you can see it, you can code it

What an awesome discussion, and great stuff for any SalesLogix developer to follow! Thanks everyone!

Want content like this delivered to your inbox? Sign up for our newsletter!
ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Hi! Excellent blog!

    I have tried to resolve the first name / last name of the current user via javascript in the onLoad function of an account form. It works with the UserId (using the WhoAmI / SOAP thing):

    var userid = xmlDoc.getElementsByTagName(“UserId”)[0].childNodes[0].nodeValue;

    See http://www.crowehorwath.com/cs/blogs/crm/archive/2008/05/08/hide-show-fields-in-crm-4-0-based-on-security-role.aspx

    How on earth do I get the first name and last name? I tried to use the information from your code, but the following didnt work:

    var userid = xmlDoc.getElementsByTagName(“User”)[0].childNodes[0].Text;

    Any ideas? Truely appreciate your help.
    Jim

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *