SAP GUIXT - Pass Variable and run script - vbscript

I would like to create an "input field" in SAP that uses the passed value within a vb script. To give a specific example, I would like to open FBL5N, pass an invoice into a field and view the invoice in VF03. The script to do that is ready and works for a hardcoded value of invoice or thru VBA.
Here is the GUI script part
inputfield (2,35) "inv" (2,45) size=10 name="V_inv"
pushbutton (toolbar) "print_inv" process="InvoiceScript.txt"
using MYINV = "V_inv"
Now, I don't know what to do for the inputscript part. I would like your assistance in this matter. Here is my first attempt:
Screen SAPLSLVC.0500
ApplyGuiScript template="VF03INV.vbs"
Enter
Thank you for your help and let me know if you need any precision.
Here are my sources of inspiration to get the above code :
http://www.synactive.com/tutor_e/lessonia03.html
http://www.synactive.com/docu_e/docia_process2.html
***if its possible to have a version that reads a value in clipboard, that would even be better.

After many attempts here is a solution:
Script(SAPLSLVC.0500.txt):
inputfield (2,35) "inv" (2,45) size=10 name="V_inv"
pushbutton (toolbar) "script" "/OVF03" process="startvf03.txt"
using INV = [V_inv] ' need this when opening new screen
InputScript (startvf03.txt):
parameter INV
Screen SAPMV60A.0101 'this is the VF03 screen
SET F[VBRK-VBELN] "&U[INV]" 'pass invoice # parameter
ApplyGuiScript "C:\guiXT\scripts\VF03INV.vbs"
VBScript (VF03INV.vbs):
inv = session.findById("wnd[0]/usr/ctxtVBRK-VBELN").text
session.findById("wnd[0]/mbar/menu[0]/menu[11]").Select
session.findById("wnd[1]/tbar[0]/btn[37]").press
session.findById("wnd[0]/tbar[0]/okcd").Text = "pdf!"
session.findById("wnd[0]").sendVKey 0
'with some little extra here on how to save a pdf in SAP
'get new strings for locations (specific to my situation)
abc = session.findById("wnd[1]/usr/cntlHTML/shellcont/shell").Browserhandle.locationURL
beg = instr(abc,"C:")
cde = mid(abc,beg,9999)
dest = "C:\111\invoices\" & inv & ".pdf"
'changing from temp to a specific folder
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyfile cde, dest
'close the open file
session.findById("wnd[1]").close
session.findById("wnd[0]").close
Set fso = nothing
*the several If Not IsObject(application) Then you usually see were not necessary, but doesn't hurt to have them.
I hope this helps everyone learn Guixt

Within the VB script with the parameter "template" can you address a GuiXT variable as follows.
for example:
msgbox "&V[V_inv]"

Related

How to get MST properties from vbscript

So, I am creating a vbscript that will read an MSI and MST file. The idea is that if the user that will run the script is testing an MSI with an MST file involved, the script should create a "report" of the new properties that this MST have.
I am able to get the properties from a regular MSI, the problem is when I am trying to get into the MST section. While doing research I found out about the _TransformView Table and this should help me to obtain this information but I think I am not sure I know how to handle that table.
Const msiTransformErrorViewTransform = 256
Const msiOpenDB = 2
Dim FS, TS, WI, DB, View, Rec
Set WI = CreateObject("WindowsInstaller.Installer")
Set DB = WI.OpenDatabase(msiPath,msiOpenDB)
DB.ApplyTransform mstPath, msiTransformErrorViewTransform
If Err.number Then
Exit Function
End If
For i = 0 To 24 'Number of properties on the arrPropertyList
Set View = DB.OpenView("Select `Value` From Property WHERE `Property` = " & "'" & arrPropertyList(i) & "'")
View.Execute
Set Rec = View.Fetch
If Not Rec Is Nothing Then
objLog.WriteLine arrPropertyList(i) & " = " & Rec.StringData(1)
End If
Next
That code will display the msi properties that I have added on the arrPropertyList. The thing is that I am looking for the MST properties and I am only getting the MSI ones. I know that I should change the Query to access the _TransformView Table when calling the DB.OpenView but not sure how can I get to this information! Any knowledge you can share would be welcome.
It works slightly differently to what you think. Run the following to see what I mean (maybe force the VBS to run with Cscript.exe from a command prompt if you're expecting a lot of output):
'create 2 constants - one for when we want to just query the MSI (read) and one for when we want to make changes (write)
Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
Const msiTransformErrorViewTransform = 256
'create WindowsInstaller.Installer object
Dim oInstaller : Set oInstaller = CreateObject("WindowsInstaller.Installer")
'open the MSI (the first argument supplied to the vbscript)
Dim oDatabase : Set oDatabase = oInstaller.OpenDatabase("C:\Temp\Temp.msi",msiOpenDatabaseModeReadOnly)
oDatabase.ApplyTransform "C:\Temp\Temp.mst", msiTransformErrorViewTransform
'create a view of the registry we want to see
Dim sql : sql = "SELECT * FROM `_TransformView`"
Dim regView : Set regView = oDatabase.OpenView(sql)
'execute the query
regView.Execute
'fetch the first row of data (if there is one!)
Dim regRecord : Set regRecord = regView.Fetch
'whilst we've returned a row and therefore regRecord is not Nothing
While Not regRecord Is Nothing
'print out the registry key
wscript.echo "Table: " & regRecord.StringData(1)
wscript.echo "Column: " & regRecord.StringData(2)
wscript.echo "Row: " & regRecord.StringData(3)
wscript.echo "Data: " & regRecord.StringData(4)
wscript.echo "Current: " & regRecord.StringData(5)
wscript.echo "***"
'go and fetch the next row of data
Set regRecord = regView.Fetch
Wend
regView.Close
Set regView = Nothing
Set regRecord = Nothing
Set oDatabase = Nothing
Set oInstaller = Nothing
So if you only wanted to see changes in the Property table, you would change the SQL query to:
Dim sql : sql = "SELECT * FROM `_TransformView` WHERE `Table` = 'Property'"
As well as storing the column names of the changed entries, the 'Column' column in the '_TransformView' table also stores whether the value was inserted, removed etc by using the values:
INSERT, DELETE, CREATE, or DROP.
You can find lots of VBScript Windows Installer tutorials for reference - don't forget to set your objects to Nothing otherwise you'll leave handles open. And of course use the link you provided for further reference.
WiLstXfm.vbs: Are you familiar with the MSI SDK sample: wilstxfm.vbs (View a Transform)? It can be used to view transform files. Usage is as follows:
cscript.exe WiLstXfm.vbs MySetup.msi MySetup.mst
Mock-up output:
Property Value [INSTALLLEVEL] {100}->{102}
File DELETE [Help.chm]
I think all you need is in there? Maybe give it a quick look. There is a whole bunch of such MSI API Samples - for all kinds of MSI purposes.
Github.com / Windows SDK: These VBScripts are installed with the Windows SDK, so you can find them on your local disk if you have Visual Studio installed, but you can also find them on Github.com:
Github: WiLstXfm.vbs - Microsoft repository on github.com.
Disk: On your local disk, search under Program Files (x86) if you have Visual Studio installed. Current Example: %ProgramFiles(x86)%\Windows Kits\10\bin\10.0.17763.0\x86.

Create and show a PDF file from a Lotus Notes action

I'm using an action inside a form to create a Word document, using the CreateObject("Word.application") method, then I modify it to my liking and save it in a temp directory.
I can show the Word document as soon as it is created by calling nameOfTheDocument.visible(true), and by modifying the Save action I can save the newly created document as a PDF, however I can't find a way to show it to the user.
Trying to call visible(true) on the PDF object results in error "Instance member VISIBLE does not exist"
Hmmm... The best and right way - use OS file association.
I'm use java way:
//Win
Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filePath);
p.waitFor();
//MacOS.*Nix
Process p = Runtime.getRuntime().exec("/usr/bin/open " + filePath);
p.waitFor();
But you can call this command on Lotusscript:
Shell({rundll32 url.dll,FileProtocolHandler } & fullFilePath,1)
'or
Shell({/usr/bin/open } & fullFilePath,1)
We have used the Shell command to launch PDFs in the past. Something like the below. The only downside to this is if the location of the executable changes (whether from upgrade or change to a different program) the code breaks.
Dim ProgPath$, FilePath$
Dim result As Integer
'Path of the executable
ProgPath$ = |"C:\Program Files (x86)\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe"|
'Path of the file to open
FilePath$ = | "C:\TestFile.PDF"|
result = Shell(ProgPath$ & FilePath$,1)

Replacing SubString values with the Replace function

The code below looks in the test folder for any files that have not been accessed in over 5 days, if it finds one it assigns mRoot the file path and then whats NOT WORKING is using the Replace method to look inside the mRoot string for the IP and replace it with the new one, I have it show me what mRoot looks like in a pop up just to make sure it changes(or doesn't). I can't seem to get the IP to change. Can anyone help out? I'm very new to VBS so I'm hoping this is obvious (whether it is doable or not). Thanks.
Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
sRoot = "\\192.168.1.104\test\"
today = Date
Set aFolder = oFileSys.GetFolder(sRoot)
Set aFiles = aFolder.Files
For Each file in aFiles
FileAccessed = FormatDateTime(file.DateLastAccessed, "2")
If DateDiff("d", FileAccessed, today) > 5 Then
Set objShell = Wscript.CreateObject("Wscript.Shell")
mRoot = file
Call Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")
objShell.Popup mRoot,, "My Popup Dialogue box"
'oFileSys.MoveFile file, mRoot
End If
Next
Try mRoot = Replace(mRoot,"\\192.168.1.104","\\192.168.1.105")

Open files with common name part

First of all, please excuse my shortcomings in presenting my issue as I haven't got much knowledge in VBA. Your help would be kindly appreciated.
I am working on a project that would imply putting the content of three different Excel files from three different sub-folders into one Excel file, and then run some macros in order to process the data they contain. Since I've already set the processing macros, my issue relies in importing the content correctly.
The problem I'm facing is that I don't have the exact names of the files I would like to open, and that they would change each month. Therefore, I can't use the "WorkBooks.Open" command that requires a precise name. However, the files have predictable name formats. For instance, one of the sub-folders will be comprised of files named "XXX-jan2013.xls", another one "january2013-XXX" and the last one "XXX-01/2013".
My goal would be to input the month and year manually, for instance “01/2013”, and then open all the files containing "January”, “jan” or “01" in their names.
Here’s what I have so far, with comments:
Sub ChosenDate()
‘It aims at opening a box in which the desired month would be written manually
Dim InputDate As String
‘These are the indications the user will get
InputDate = InputBox(Prompt:="Please choose a month.", _
Title:="Date", Default:="MM/YYYY")
‘In case the person forgets to write what he’s asked to
If InputDate = "MM/YYYY" Or _
InputDate = vbNullString Then
Exit Sub
‘If he does it correctly, I call the second Sub
Else: Call FilesOpening
End If
End Sub
‘So far, everything works fine
Public Sub FilesOpening()
‘This one aims at opening the chosen files
Dim ThisFile As String
Dim Files As String
‘Defining the folder in which the file is, as it can change from a computer to another
ThisFile = ThisWorkbook.Path
‘Here’s where I start struggling and where the macro doesn’t work anymore
‘If I wanted to open all the files of the folder, I would just write that:
Files = Dir(ThisFile & "\*.xls")
‘You never know…
On Error Resume Next
‘Creating the Loop
Do While Files <> vbNullString
Files = Dir
Set wbBook = Workbooks.Open(ThisWorkbook.Path & "\" & Files)
Loop
End Sub
‘But it doesn’t look inside of sub-folders, neither does it consider the date
Sub DataProcess()
‘This one is fine, except I can’t find a way to name the files correctly. Here’s the beginning:
Windows("I don’t know the name.xls").Activate
Sheets("Rapport 1").Select
Cells.Select
Selection.Copy
Windows("The File I Want To Put Data In.xlsm").Activate
Sheets("Where I Want To Put It").Select
Range("A1").Select
ActiveSheet.Paste
Windows("I don’t know the name.xls").Close
‘How can I get the name?
I hope my statement is understandable.
Thank you very much in advance!
Have a nice day,
E.
You need to build a list of the paths and the expected file masks. You can then loop each matching file and do your stuff.
Sub foo()
Dim request As String: request = "01/2013"
'//make a date
Dim asDate As Date: asDate = "01/" & request
Dim dirs(2) As String, masks(2) As String
dirs(0) = "c:\xxx\dir1\"
masks(0) = "*" & Format$(asDate, "mmmmyyyy") & "*.xls"
dirs(1) = "c:\xxx\dir2\"
masks(1) = "*" & Format$(asDate, "mmmyyyy") & "*.xls"
dirs(2) = "c:\xxx\dir3\"
masks(2) = "*" & Format$(asDate, "mmyyyy") & "*.xls"
Dim i As Long
For i = 0 To UBound(dirs)
GetFiles dirs(i), masks(i)
Next
End Sub
Private Function GetFiles(path As String, mask As String)
Dim file As String
'//loop matching files
file = Dir$(path & mask)
Do Until Len(file) = 0
'//process match
process path & file
file = Dir$()
Loop
End Function
Sub process(filePath As String)
MsgBox "processing " & filePath
'workbook.open
End Sub
As "XXX-01/2013" is not a file name I assumed "XXX-012013".
If its another subdirectory just:
dirs(x) = "c:\xxx\dir3\" & Format$(asDate, "mm") & "\"
masks(x) = "*" & year(asDate) & "*.xls"

How do I load data into the Data Portal of DIAdem with VBScript?

I want to load a ".tdm" file into DIAdem (National Instruments) with a VBScript but can't find how to do this. I have Dialog which opens a browse-window, which returns the path as a string. So I was hoping to have a function which would work something like this:
Call Data.Root.ChannelGroups.Load(myStringWithThePath)
Just noticed I got a tumbleweed-badge on this question. Here is the solution I found last week, so if anybody cares:
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "TDM-Datei(*.tdm)|*.tdm|All Files (*.*)|*.*"
objDialog.FilterIndex = 1
boolResult = objDialog.ShowOpen
If boolResult <> 0 Then
Call Data.Root.ChannelGroups.RemoveAll()
Call DataDelAll
Call DataFileLoad(objDialog.FileName)
End If

Resources