我目前正在尝试自动化从源系统(Apptio)到目标系统(PCM)的Feed。我本质上是尝试使用内置API将.tsv文件下载到共享驱动器位置,然后触发导入作业将该文件处理为PCM。
我有点坚持调用API并将文件下载然后尝试了一些方法,其中一种方法可行但我认为不太可靠。
我尝试使用wscript.exe从CMD提示符调用以下VBScript ...
Dim oXMLHTTP
Dim oStream
dim urlstr
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
urlstr = "https://SITE.apptio.com/biit/api/v1.tsv?date=Apr%3AFY2013&dataPath=-%40CSITE.co.uk%253AService%2BCosting%2Bv2%2FReports%2F.DateGoesHere%2FCostModels%2FDefault%2F.View%253Atab%253AService%2BCosting%2F.View%253AApptio%2BSandbox%2F.View%253"
urlstr = urlstr & "AABM%2FABM%2BOutput%2F%21GROUPBY%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%255D%2F.Summary%2F%21NEWCOLUMN%255B%257BLTM%2BFixed%257D%253DPreviousYear%28Fixed%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BSemi%2BVariable%257D%253DPreviousYear%28Semi%2BVariable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BVariable%257D%253DPreviousYear%28Variable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BCost%257D%253DPreviousYear%28Cost%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21SORT%255B%257BLTM%2BCost%257D%257Cdesc%255D%2F%21LIMIT%255B0%252C2147483647%252Cadd_total%255D%2F%21LIMIT_COLUMNS%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%252C%257BLTM%2BFixed%257D%252C%257BLTM%2BSemi%2BVariable%257D%252C%257BLTM%2BVariable%257D%252C%257BLTM%2BCost%257D%255D%255B%255D%255B%255D%255B'orderByIncludeList%255D"
oXMLHTTP.Open "GET", urlstr, False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oXMLHTTP.responseBody
oStream.SaveToFile "\\csdatg08\FinanceTransformationFM\Transformation\Josh\ABM Transfer\Apptio\DataFeed\Output.tsv"
oStream.Close
End If
然而,这给了我一个错误:
(12,1)msxml3.dll:访问被拒绝。
我认为这与我称之为API的事实有关。我已经尝试使用托管在同一服务器上的图形的URL,这将下载指定的位置而不会出现问题。
我也尝试将URl直接粘贴到浏览器中。 URL提示用户进行身份验证(我期望),但随后会弹出另存为对话框,显示URL正确无误。
所以..然后我尝试了一个脚本来启动IE实例,允许登录提示,等待另存为对话框然后发送密钥来保存文件。
虽然这确实有用 - 但我不相信。我> E如果进程是在不同版本的I.E上运行会发生什么,当对话框打开时会发生另一种保存....
所以我想看看是否有人知道一个更好的方法,然后我们走下完整的SQL链接路由,这将是非常昂贵的,并且可能对我们正在做的事情过度。
谢谢
(第二段代码如下)
Dim objExplorer : Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "https://SITE.apptio.com/biit/api/v1.tsv?date=Apr%3AFY2013&dataPath=-%40CSITE.co.uk%253AService%2BCosting%2Bv2%2FReports%2F.DateGoesHere%2FCostModels%2FDefault%2F.View%253Atab%253AService%2BCosting%2F.View%253AApptio%2BSandbox%2F.View%253AABM%2FABM%2BOutput%2F%21GROUPBY%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%255D%2F.Summary%2F%21NEWCOLUMN%255B%257BLTM%2BFixed%257D%253DPreviousYear%28Fixed%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BSemi%2BVariable%257D%253DPreviousYear%28Semi%2BVariable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BVariable%257D%253DPreviousYear%28Variable%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21NEWCOLUMN%255B%257BLTM%2BCost%257D%253DPreviousYear%28Cost%29%255D%255B%253DCurrency%28%2524_%29%255D%2F%21SORT%255B%257BLTM%2BCost%257D%257Cdesc%255D%2F%21LIMIT%255B0%252C2147483647%252Cadd_total%255D%2F%21LIMIT_COLUMNS%255B%257BABM%2BOutput.Account%2BProcess%257D%252C%257BABM%2BOutput.Channel%257D%252C%257BABM%2BOutput.Product%257D%252C%257BLTM%2BFixed%257D%252C%257BLTM%2BSemi%2BVariable%257D%252C%257BLTM%2BVariable%257D%252C%257BLTM%2BCost%257D%255D%255B%255D%255B%255D%255BorderByIncludeList%255D"
objExplorer.ToolBar = 1
objExplorer.StatusBar = 1
objExplorer.Width = 800
objExplorer.Height = 800
objExplorer.Left = 1
objExplorer.Top = 1
objExplorer.Visible = 1
wscript.echo "window open"
wscript.sleep 6000
Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("File Download")
If ret = True Then
wshShell.SendKeys "%S"
Exit Do
End If
WScript.Sleep 500
Loop
wscript.echo "Save Selected"
Do
ret = wshShell.AppActivate("Save As")
If ret = True Then
wshShell.SendKeys "%S"
Exit Do
End If
WScript.Sleep 500
Loop
wscript.echo "File Saved"
到目前为止的参考文献:
how to handle IE Download dialog with VB Script? VBScript to detect an open messagebox and close it http://www.pctools.com/guides/scripting/detail/149/?act=reference