Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sbumeshqlik
Contributor III
Contributor III

Need to call webservice macro from load script

Hello,

In my QV,  I have  macro to call  webservice 

function getAirportWSDL(vInput)

   

vURL = "http://www.webservicex.com/airport.asmx/getAirportInformationByISOCountryCode?CountryAbbrviation="+ vInput

    'set txt1 = ActiveDocument.Variables("vXMLSent")

    'txt1.setContent "Null", true

    'Create xmlhttp opject

    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")

    xmlhttp.open "GET", vURL, false

    xmlhttp.setRequestHeader "Content-Type", "text/xml"

    xmlhttp.send ""

    result = xmlhttp.responseText

   

    result = replace(result, ">", ">")

    result = replace(result, "&lt;", "<")

    

    set txt = ActiveDocument.Variables("vXMLReceived")

    txt.setContent result, true

    'getAirportWSDL = vInput

End Function 

-----------------------------------------------------------------------------------------

in my load script,after  reloading,   it is not fetching any values to vXMLReceived

let vXMLReceived  = ' ';

LET Creat =   getAirportWSDL( 'BH');

Any help, would be appreciated.

Regards,

Umesh.

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

You should consider Toni's good advice since a load statement will help you parse the XML properly. If you tell more about how you intend to use the data in your application it would be easier for us to give you further advice.

For a small XML-payload like this service it is rather straight forward anyway to parse it manually. Where do you prefer to have the code? In the load script or in VBScript? VBScript has some limitations as to how you can run it and how efficiently it will run on a server. If you do everything in the load script it will be quite easy to do the same in Qlik Sense in the future whereas a VBScript solution has to be converted.

View solution in original post

11 Replies
petter
Partner - Champion III
Partner - Champion III

You can't access the ActiveDocument from a VBscript-function that you call from a Load Script. The ActiveDocument hasn't been intialized yet. So you will have to return the result as a return result from the function:

      getAirportWSDL = result

End Function



and then the variable Creat get the result as a value.

LET Creat = getAirportWSDL('BH');

I would suggest that you rename the variable to resultAirport

LET resultAirport = getAirportWSDL('BH');

This variable you can easily access in your application once the Load Script has finished running and the application has started.

petter
Partner - Champion III
Partner - Champion III

2015-05-17 #1.PNG

2015-05-17 #2.PNG

2015-05-17 #3.PNG

ToniKautto
Employee
Employee

It looks like your macro only makes a HTTP GET to a web source and retrieves XML data. Why do you not just load this as an XML source directly in the load script?

sbumeshqlik
Contributor III
Contributor III
Author

Hi Peter,

Thanks, a lot.

Would, appreciate, if you Can please let me know how to  parse xml string resultAirportXML.

petter
Partner - Champion III
Partner - Champion III

You should consider Toni's good advice since a load statement will help you parse the XML properly. If you tell more about how you intend to use the data in your application it would be easier for us to give you further advice.

For a small XML-payload like this service it is rather straight forward anyway to parse it manually. Where do you prefer to have the code? In the load script or in VBScript? VBScript has some limitations as to how you can run it and how efficiently it will run on a server. If you do everything in the load script it will be quite easy to do the same in Qlik Sense in the future whereas a VBScript solution has to be converted.

sbumeshqlik
Contributor III
Contributor III
Author

Hi Peter,

Thanks, in that case,  would prefer to have, XML string parsing, in QV LOAD script.

petter
Partner - Champion III
Partner - Champion III

If you consider your question answered you could close this thread and I will have something for you on your new question on how to parse XML in the Load Script.

sbumeshqlik
Contributor III
Contributor III
Author

Hi Peter,

Thanks.

petter
Partner - Champion III
Partner - Champion III

If you start a new question with for example "XML string parsing, in QV LOAD script" as a title - I can respond and upload something I have as a response to that.

Thanks