How can I clear all the SAP GUI fields when I open a T-Code? - sap-gui

When I open a T-Code from SAP GUI, some of the fields are pre-populated from past queries. Is it possible to enter a T-Code and all the fields in the next window to be forced blank?
I develop scripts for SAP GUI and run into problems if fields already have content from prior queries.

The history cannot be disabled user-wise. Period.
Either all or nobody.
If you want to disable the history go to SAPgui options into Local data setting
The history in Windows is a simple Access MDB file but it is password-protected, so you may try to crack it and delete only your user lines but it is a bunch of work.
However, I guess the history that makes you crazy is not what I described above, but SPA/GPA parameters. Check it first

You can empty some fields with :
""
session.findById("wnd[1]/usr/ctxtRMMG1_REF-BWTAR").Text = ""
But doesn't work all the time...

My method for this is to loop through all the fields (and recursively on all children elements) and set the text value of them to an empty string.
On read-only fields it throws an error and this is why "On Error Resume Next" is necessary.
Sub Start_Clearing()
'setup SAP
If Not IsObject(SAPApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApplication.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject Session, "on"
WScript.ConnectObject SAPApplication, "on"
End If
Dim UserArea As Object
Set UserArea = Session.findByID("wnd[0]/usr")
Clear_Fields UserArea
End Sub
'_______________________________
Sub Clear_Fields(Area As Object)
Set SAPApplication = GetObject("SAPGUI").GetScriptingEngine
Dim Obj As Object
Dim NextArea As Object
On Error Resume Next
For i = 0 To Area.Children.Count - 1
Set Obj = Area.Children(CInt(i))
If Obj.ContainerType = True Then
If Obj.Children.Count > 0 Then
Set NextArea = SAPApplication.findByID(Obj.ID)
Clear_Fields NextArea
End If
End If
Obj.Text = ""
Next i
End Sub

Related

Scroll to the end of the page in SAP GUI

I'm trying to automate my SAP GUI until the end of the page and I got the code below from this site https://www.appsloveworld.com/vba/200/144/algorithm-for-finding-end-of-a-list-sap-gui
I only changed the text after findById but I get this error at the line which changes verticalScrollbar.Position:
object doesn't support this property or method
Any ideas on how to solve that?
Do While Not blank
If session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").Text = "" _
Then blank = True
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").verticalScrollbar.Position = i
i = i + 1
Loop

Getting documents of last 25 minutes with formula and lotusscript

In lotus I have a view with order documents.
I am building an agent to search for all orders which are modified in the last 25 minutes.
For this I have done code like:
strFormule = "Form=""Order"" & #Modified >= #Adjust(#Today;0;0;0;0;-25;0) & Deleted !=""J"""
Set ndcOrder = currentDB.Search( strFormule, Nothing, 0 )
If ndcOrder.Count <> 0 Then
Set doc = ndcOrder.GetFirstDocument
While Not doc Is Nothing
So if it is 11.00 then it need to take orders which are modified today from 10.35
But in the debugger I also get orders which where modified 2 hours earlier.
How is this possible?
I think it's might be because you're using #today which doesn't have a time element. Try #Now instead ?
In the past I used the LotusScript method GetModifiedDocuments which lets you specify a NotesDateTime object to retrieve any document modified since.
Your code could then look like this:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As notesdocumentcollection
Dim since As New NotesDateTime("")
Set db = session.CurrentDatabase
Call since.SetNow()
Call since.AdjustMinute(-25)
Set dc = db.GetModifiedDocuments(since)
My experience with this method was very good so far. More info on GetModifiedDocuments
Why use formula at all?
I would create a hidden view, first column is last modified date-time, sorted descending.
Then I would write my Lotusscript code to start at the top and work its way down until it encounters a date/time value that is older than 25 minutes ago.
Something like this:
Dim docs List As NotesDocument
Set dt25 = New NotesDateEntry(Now())
Call dt25.AdjustMinutes(-25)
Dim col as NotesViewEntryCollection
Dim entry as NotesViewEntry
Set col = view.AllEntries
Set entry = col.GetFirstEntry
Do Until entry Is Nothing
If Cdat(entry.ColumnValues(0))<Cdat(dt25.LSLocalTime) Then
Exit Loop
End If
Set docs(entry.Document.UniversalID) = entry.Document
Loop
' Now you have a list of documents created in the last 25 minutes.

Time management of a script asp

within a page ASP (classic) I have a function that connects to the server via XMLHTTP to google to get the time and distance between two points.
I noticed that sometimes my server makes this request very slowly sending the script out and blocking the page.
I would therefore ask you.
If I change the attached script to say
if the execution time exceeds five seconds then stops the script
function GooDistInd(origine,destintario)
Set objxml = Nothing
' Dichiaro le variabili che mi servono nello script
Dim file, objXmlHttp, objXmlDom, distanza, cognome, i
'http://maps.google.com/maps/api/directions/xml?origin=40.7143528,-74.0059731&destination=40.7035458,-74.21607971&sensor=false
file = "http://maps.googleapis.com/maps/api/directions/xml?origin="& origine &"destination="&destintario &"&sensor=false"
Set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
objXmlHttp.Open "GET", file, False
objXmlHttp.Send
Set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
objXmlDom.async = False
objXmlDom.loadXML(objXmlHttp.responseText)
Set tempo = objXmlDom.getElementsByTagName("leg/distance/value")
i = 0
For i = 0 To tempo.length - 1
distanza=tempo(i).Text
exit for
Next
GooDistInd =distanza
end function
If you want to stop the script completely you could use
Server.ScriptTimeout = 5
You could also use the timeut property of the Microsoft.XMLHTTP object and set it to 5000 ms. In this case you could work with on error resume next and check if an error occurred, so you could give back a significant error message to you users

Having classic ASP read in a key from appsettings in a web.config file

OK so here's the situation. I've got a classic ASP website running inside an MVC 4 application. I need the classic ASP website to be able to get a key from the appsettings section of the web.config file.
Here is the function I've got:
' Imports a site string from an xml file (usually web.config)
Function ImportMySite(webConfig, attrName, reformatMSN)
Dim oXML, oNode, oChild, oAttr, dsn
Set oXML=Server.CreateObject("Microsoft.XMLDOM")
oXML.Async = "false"
oXML.Load(Server.MapPath(webConfig))
Set oNode = oXML.GetElementsByTagName("appSettings").Item(0)
Set oChild = oNode.GetElementsByTagName("add")
' Get the first match
For Each oAttr in oChild
If oAttr.getAttribute("key") = attrName then
dsn = oAttr.getAttribute("mysite")
ImportMySite = dsn
Exit Function
End If
Next
End Function
Here is the function call code:
msn = ImportMySite("web.config", "mysite", false)
So when I call this function the value I get back is always blank or null. I'm not sure where I'm going wrong, I'm a total novice with XML so maybe I'm missing something completely obvious. I have searched the questions but couldn't find anything related to this using classic ASP.
Any help would be much appreciated.
I appreciate Connor's work. It got me well along the way to making this happen. I made some changes that I think might be helpful to others.
I did not want to have to repeat the file name for each call and I have a couple of sections in my config. This seemed more general. Also, I consolidated his changes into a for-sure working example. You can paste this into your app, change the CONFIG_FILE_PATH and get on with your life.
'******************************GetConfigValue*******************************
' Purpose: Utility function to get value from a configuration file.
' Conditions: CONFIG_FILE_PATH must be refer to a valid XML file
' Input: sectionName - a section in the file, eg, appSettings
' attrName - refers to the "key" attribute of an entry
' Output: A string containing the value of the appropriate entry
'***************************************************************************
CONFIG_FILE_PATH="Web.config" 'if no qualifier, refers to this directory. can point elsewhere.
Function GetConfigValue(sectionName, attrName)
Dim oXML, oNode, oChild, oAttr, dsn
Set oXML=Server.CreateObject("Microsoft.XMLDOM")
oXML.Async = "false"
oXML.Load(Server.MapPath(CONFIG_FILE_PATH))
Set oNode = oXML.GetElementsByTagName(sectionName).Item(0)
Set oChild = oNode.GetElementsByTagName("add")
' Get the first match
For Each oAttr in oChild
If oAttr.getAttribute("key") = attrName then
dsn = oAttr.getAttribute("value")
GetConfigValue = dsn
Exit Function
End If
Next
End Function
settingValue = GetConfigValue("appSettings", "someKeyName")
Response.Write(settingValue)
OK I found my answer.
I changed:
For Each oAttr in oChild
If oAttr.getAttribute("key") = attrName then
dsn = oAttr.getAttribute("mysite")
ImportMySite = dsn
Exit Function
End If
Next
To:
For Each oAttr in oChild
If oAttr.getAttribute("key") = attrName then
dsn = oAttr.getAttribute("value")
ImportMySite = dsn
Exit Function
End If
Next

Database Editing in Session OnEnd Classic ASP

I was Creating a website in Classic ASP Project, having a Logout feature.
I want to access the login database and make changes, when the session ends. The coding is something like:
In global.asa :
Sub Session_OnEnd()
Set studcon = Server.CreateObject("ADODB.Connection")
studcon.Open "Provider = Microsoft.JET.OLEDB.4.0;Data Source = E:\mailfan.mdb"
Set studrec = Server.CreateObject("ADODB.Recordset")
studrec.Open "login", studcon, 1, 3
studrec.movefirst
found = 0
Do While studrec.EOF or found = 1
If studrec("ID") = Session("uid") Then
studrec("log") = 0
studrec.Update
End If
studrec.movenext
Loop
studrec.close
studcon.close
Set studrec = Nothing
Set studcon = Nothing
End Sub
But Even After Session.Abandon the value of log field Remains the same (It is 1 when session's active).
Small Update: I tried to google it, and did recieve a very similar link having the same question: http://www.justskins.com/forums/problem-with-global-asa-77015.html
But the code is the same as suggested by Aaron Bertrand in the above link. Is it due to IIS 8.0? Because I would be Running it on Win XP sp3 IIS 6. And I Do require it to work there.
I can't see an SQL query anywhere in your code. If you're intent on using a recordset for your update then in place of
studrec.Open "login", studcon, 1, 3
you should have something like
studrec.Open "select * from login", studcon, 1, 3
This assumes that your database table is called "Login"
Using a recordset is actually an over complex means of doing all this though, An Update query should suffice. You could remove all your code from
Set studrec = Server.CreateObject("ADODB.Recordset")
to
studrec.close
and replace it with
studcon.Execute("UPDATE Login set log = 0 where id = " & Session("uid"))

Resources