Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am currently trying to integrate a web service call into a Qlik application. I have successfully done this with a Macro that is triggered by a button. The xml response from the web service is saved to a temporary file, a partial reload is done, and the temporary file is deleted. I found a few helpful posts on the Qlik community to set it up. Here is the relevant portion of the macro code:
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST",<endpoint>,false
xmlhttp.send xmlToSend
Path = ActiveDocument.Evaluate("left(DocumentPath(), index(DocumentPath(), '\', -1))")
FileName = Path & "response.xml"
set fso = CreateObject("Scripting.FileSystemObject")
set s = fso.CreateTextFile(FileName, True)
s.writeline(result)
s.Close()
ActiveDocument.DoReload 2, true
fso.DeleteFile(FileName)
My question is how would I get this to work outside of the Desktop application so that any user accessing the .qvw through AccessPoint is also able to use web service data? I have not found a way to trigger any sort of reload from within the .qvw on AccessPoioint (DoReload or any of the other Reload functions for ActiveDocument and the Reload action for a button). I am able to call the web service from AccessPoint and can set the return value into a variable but I am not able to get the xml response to be reloaded into the appropriate tables for my visualizations. Most of the data can be a day old but we are trying to use a web service to provide a real-time option for the user. I think there may be a way to do this by manually parsing the xml within the macro and using the DynamicUpdateCommand but I am looking for something that feels a little less "hacky". Any tips or examples would be greatly appreciated.
Hi Nick,
Can you please share the whole macro,I am also trying something similar ,creating csv file thru web service.thank a lot
Sure, here is the complete macro (with company identifying info removed). This is VBScript and you will want to set the security to System Access/Allow System Access. You will want to get xmlToSend to match the xml you send through soapUI (or whatever testing tool you use) and change <endpoint> to the endpoint you want to send your request to.
Sub WS
mrn = ActiveDocument.Fields("MRN").GetPossibleValues.Item(0).Text
xmlToSend = ""
xmlToSend = xmlToSend & "<?xml version='1.0' encoding='utf-8'?>"
xmlToSend = xmlToSend & "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:v4='ptnt_care/hlth_info_gthr/epic/lab_orders/v4'>"
xmlToSend = xmlToSend & "<soapenv:Header/>"
xmlToSend = xmlToSend & "<soapenv:Body>"
xmlToSend = xmlToSend & "<v4:getLabResults>"
xmlToSend = xmlToSend & ("<v4:mrn>" & mrn & "</v4:mrn>")
xmlToSend = xmlToSend & "</v4:getLabResults>"
xmlToSend = xmlToSend & "</soapenv:Body>"
xmlToSend = xmlToSend & "</soapenv:Envelope>"
'Create xmlhttp opject
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST", <endpoint>, false
xmlhttp.send xmlToSend
result = xmlhttp.responseText
result = replace(result, ">", ">")
result = replace(result, "<", "<")
Path = ActiveDocument.Evaluate("left(DocumentPath(), index(DocumentPath(), '\', -1))")
FileName = Path & "response.xml"
set fso = CreateObject("Scripting.FileSystemObject")
set s = fso.CreateTextFile(FileName, True)
s.writeline(result)
s.Close()
'Load document with the temp file - DoReload will not show progress dialog
ActiveDocument.DoReload 2, true
'Delete the temp file
fso.DeleteFile(FileName)
End Sub
Did you find a solution? I was able to call a similar macro in the load script, but the AccessPoint / Publisher refuses to execute the macro.