GUI scripting question -am I sunk?

Hi all,
I am working on an Applescript to bring up two different non-Applescript-able applications (ie. ones w/o a dictionary) and am getting the error:
NSReceiverEvaluationScriptError : 4 from Applescript.
I have "Enable access for assitive devices" checked in SystemPreferences and am GUI scripting.
Here's the snippet of code that gives the error:
tell application "System Events"
if UI elements enabled then
activate application "TRx Recorder"
tell button " Record " of tool bar 1 of window "TRx Recorder"
click
end tell
end if
end tell
I generated the code "tell button ..." from the Prefab's UI Browser.
I've tried clicking via the name of the button, and via the position of the button. Same error.
Does this mean I'm sunk and can't get the app to respond to my Applescript?
When I select the Action of button " Record " from within the UI Browser, it works fine.
What am I doing wrong?
Thanks!
Ed

Hi Camelot,
Yes indeed I needed a "tell process ..." block, as well as, 2 extra spaces in the label for the Record button.
I got the following to work:
tell application "System Events"
if UI elements enabled then
activate application "TRx Recorder"
tell process "TRx Recorder"
click button " Record " of tool bar 1 of window "TRx Recorder"
end tell
end if
end tell
I dug around using UI Browser and discovered that I needed 2 blanks in front of and 2 blanks behind of the label "Record" to correctly access the button. I originally had 1 space in front of Record and 1 space after Record within the quotes. With only 1 space I get the Applescript error I mentioned. With 2 I don't get the error.
Many thanks for the tip, it made me look closer at the labels of the buttons in UI Browser.
Ed

Similar Messages

  • GUI scripting question -am I sunk? Part 2

    Hi all,
    I am trying to get two apps that have no Applescript dictionary entries to respond to an Applescript I am writing. I want to first bring up an audio app, then bring up a transcripting app and pass to this second app the new audio filename the first app created.
    I've got the script to bring up the audio app, create the new audio file, run a couple of Perl scripts to grab the new audio filename and pass it back to Applescript and start the second app.
    I can't get the second app to respond to anything but activate in Applescript. When I try to get a menu item selected, or clicked, either nothing happens, or the transcript app pops up an error window w/ the message "Nil Object Exception" which is bad.
    I also tried using PreFab's UI Browser to get the same menu action I want to execute by pressing the "Perform" button in the UI Browser. Nothing happens in that case as well.
    Here's the code snippet in question:
    If (InqScribeUp is false) then
    activate application "InqScribe"
    end if
    tell process "InqScribe"
    click menu item "New Document with Media File..." of menu 1 of menu bar item "File" of menu bar 1
    end tell
    The boolean variable InqScribeUp is defined earlier in the script.
    When the above script is executed nothing happens.
    If I change the statement "click menu item ..." to a tell block:
    tell menu item "New Document with Media File..." of menu 1 of menu bar item "File" of menu bar 1
    click
    end tell
    I get the "Nil Object Exception" error from the transcript app InqScribe.
    When I try using the "Perform" button in the UI Browser on the first audio app, the audio app does respond fine.
    Am I now really stuck if the second app doesn't even respond to UI Browser's "Perform"?
    Any ideas would be greatly appreciated!
    Ed

    Hi Budgie,
    The try block didn't work for me. I tested further and found I needed a sleep command between running the Perl scripts and bringing up InqScribe. The need to wait may be because I'm testing on an old PM G4 dual 867MHz machine, not a newer multi-GHz CPU.
    Anyway, after putting in a sleep 20 in the second Perl script (which I "think I can reduce to 7-9), I was able to get the dialog window "Select a Media File" to be displayed upon sending InqScribe the shortcut key for that dialog window. I tried the "click ..." statement but no go, InqScribe didn't respond. Sending InqScribe the sortcut key event did work for some reason.
    To complete the loop, I need to select a specific audio file in the dialog window "Select a Media File". By using the UI Browser, I've narrowed the statement I need to:
    select static text NewFile of group TrxFileCount of list 1 of scroll area 5 of scroll area 1 of browser 1 of group 1 of window "Select a Media File"
    where NewFile is a string variable containing the name of the latest audio file just created, and TrxFileCount is an integer with the value of the no. of files in the folder where the audio files for the app are located.
    I now get an error from SystemEvents: NSReceiverEvaluationScriptError: 4, which I take to mean SystemEvents can't find the static text element I'm trying to select.
    Should I try to "set" the value of the static text element instead? Or "select" it via it's position on the screen?
    Here's my code snippet so far:
    set NewFile to RetCode
    If (InqScribeUp is false) then
    activate application "InqScribe"
    end if
    keystroke "D" using command down
    sleep 5
    set TRxFileCount to count of (files in folder TRxRecordings whose name extension is "wav")
    select static text NewFile of group TRxFileCount of list 1 of scroll area 5 of scroll area 1 of browser 1 of group 1 of window "Select a Media File"
    click button "Open" of window "Select a Media File"
    The error now occurs on the "select ..." statement, I don't get to the final "click button "Open"..." statement.
    Any ideas at this point would be greatly appreciated!
    Ed

  • SAP GUI Scripting Wizzard Windows7 does not work

    Dear Experts,
    I am quite a novice when it comes to SAP GUI scripting (let alone any other development), therefore my question might be rather stupid. After my PC was migrated from XP to Windows 7 it is no longer possible to use the SAP GUI scripting wizzard. When you select it from the menue, simply nothing happens.
    Does anyone have an idea what I need to do to have this useful tool back on my PC?
    We are running SAP GUi 7.1
    Thanks for your help
    Theo

      Here is SAP GUI wizard replacement tool...its in auto IT - enjoy
    http://www.autoitscript.com/forum/topic/149540-sapwizardudf/
    I had the tech guys here install ,  the latest GUI patch level 15,
    and the script development tools not working issue has been fixed
    They (SAP?) removed the 'script development tools' menu option!?
    I have not installed the MS hotfix, but
    My question is,  it true the 'Script development tools' is gone?
    Other methods
    a) This (free) non SAP solution seems to work however...any other ideas?
    Scripting Tracker Lite
    http://scn.sap.com/docs/DOC-32728
    b) The Activate GuiXT tool in SAP GUI also does give you some clues in the element window
    and could be an alternative way , to get control names.
    eg a radio button is R[P_CONTROL_ID] when it should be radP_CONTROL_ID
    c) The SAP script recording and playback ,  to a vbs script will give you the control names also, if you edit the script.
    You must of course have GUI scripting on in rz11
    I can't read this note https://service.sap.com/sap/support/notes/1633639 - need a password!

  • SAP GUI Scripting: Script Is Running.....Help!

    Hello all,
    I'm new to the forums and have an SAP question problem. I'm an end user of SAP and have been using it since 2002. A couple of weeks ago when I logged into SAP I noticed a red/white icon in the lower right corner of my screen. When I hover over it it says "SAP GUI Scripting: Script Is Running". The problem is, I have never created a script. When I start working in SAP I have noticed a lot of the screens have a different format now and I get a lot of ABAP errors.
    After doing some research I found under "Customize Local Layout", "Options" I can uncheck the box "Enable Scripting". I click "Apply" and "OK". Now the red/white icon goes away in the lower right corner and all my screens go back to normal with no ABAP errors.
    The problem now is that every minute or two I get a pop up window that says "Scripting support is disabled by the user".
    Has anyone else had this problem?
    1. I've never created a script. Why is one running now?
    2. Is there a way to stop the pop up message "Scripting support is disabled...." if I uncheck "Enable Scripting"?
    Thanks for any feedback

    Here's the properties of the connection....
    http://www.lstwo.com/images/97735141499811194923.jpg
    http://www.lstwo.com/images/27092678568585605702.jpg
    http://www.lstwo.com/images/02572789823840845106.jpg
    Here's the properties of the desktop icon....
    http://www.lstwo.com/images/36703668322706084468.jpg
    http://www.lstwo.com/images/40729387005252851113.jpg
    http://www.lstwo.com/images/48149337890555671928.jpg
    I agree, I'm stumped. I even tried looking through the SAP entries in my registry to see if I could find anything. It's a bit confusing but I didn't see anything out of place.

  • Tool Tip / GUI-script battle

    I've got a slider that invokes a handler that performs some AppleScript GUI scripting ( ... unfortunate, yes, but there's no other way.)
    The slider has a Tool Tip.
    If I click and drag outside of the slider's mouseDown region, no problem. The GUI stuff works as expected.
    If I drag inside the slider's mouseDown region, the ToolTip appears at it designated time, as if I were hovering. This causes a NSReceiverEvaluationScriptError: 4 (1) error. Certainly makes sense that I'd get an error when the Tool Tip comes to the front. But I'm confused as to why it appears. None of my non-GUI related sliders have this problem.
    Suggestions?
    Here are a few other Tool Tip questions:
    1) Can I increase or decrease the display length for all tool tips?
    2) Is it possible to keep tool tips visible indefinitely while the user hovers the mouse over the object, closing on mouseLeave?
    3) Can I toggle all Tool Tips to enabled or disabled?
    Thanks, John

    I've got a slider that invokes a handler that
    performs some AppleScript GUI scripting ( ...
    unfortunate, yes, but there's no other way.)
    The slider has a Tool Tip.
    If I click and drag outside of the slider's mouseDown
    region, no problem. The GUI stuff works as expected.
    If I drag inside the slider's mouseDown region, the
    ToolTip appears at it designated time, as if I were
    hovering. This causes a
    NSReceiverEvaluationScriptError: 4 (1) error.
    Certainly makes sense that I'd get an error when the
    Tool Tip comes to the front. But I'm confused as to
    why it appears. None of my non-GUI related sliders
    have this problem.
    Suggestions?
    Just noticed: on another computer (a powerBook) I get the NSReceiver error at any click or drag. Cleaned all targets and got the same result.
    I set a one second delay to make sure the GUI window gets time to come to the front but to no avail. There's a error at every click or drag.
    John

  • Need help with GUI Scripting Audio Midi Setup

    I want to read the value of the sampling frequency set by default in Audio Midi Setup.
    If there is an easy unix way to gleen this, please let me know. Otherwise, I am trying to get it via GUI scripting. I think I am almost there, but am doing something stupid.
    Here is what I have:
    tell application "Audio MIDI Setup"
    activate
    end tell
    tell application "System Events"
    activate
    tell application process "Audio MIDI Setup"
    select window 1
    select group
    select tab group
    select group
    select combo box
    set FrequencyValue to contents of combo box
    end tell
    end tell
    Basically, this comes down to the question of how to extract the default text field from the combo box.

    Once you click on the combo box to get the list of items, you can do stuff with the results. The easiest thing would probably be to use the up and down arrows to change the selection, since the text field is not editable. You can compare the list of items with the current value and do something from there - how do you plan to choose the item to change to?
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Audio MIDI Setup" to activate
    tell application "System Events" to tell application process "Audio MIDI Setup"
    set comboBox to combo box 1 of group 1 of tab group 1 of group 1 of window "Audio Devices"
    set frequencyValue to value of comboBox -- get current value
    click button 1 of comboBox -- perform action "AXPress" to drop the list
    set theChoices to value of text fields of list 1 of scroll area 1 of comboBox -- get all the values
    -- keystroke (ASCII character 31) -- down arrow
    -- keystroke (ASCII character 30) -- up arrow
    -- keystroke return -- select and dismiss the list
    end tell
    activate me
    choose from list theChoices default items {frequencyValue} -- just show the results
    </pre>

  • Error in executing eCATT GUI Script

    Hi
    I am getting following error (in bold) while executing eCATT GUI Script. This happens only for GUI Scripts and not for TCD scripts. Please help me to solve this issue.
    <b>0000000195  Test Scrpt ZGUI_SCRIPT4 Version 1 - SECATT [Without Interruption]
    R01 800 SANDEEPK1 E 620 sapnw10 Windows NT MSSQL 26.05.2006 12:42:29
    ZGUI_SCRIPT4 [0,109 sec] Version 1 ZGUI_SCRIPT4
    Tgt System TEST_ECAT->ECATT_SAPNW10_800_E->T90CLNT090 (R01 800 ALEREMOTE E 620 sapnw10
    Windows NT MSSQL)
    Error in eCATT function SAPGUI
    Destination ECATT_SAPNW10_800_E RFC error
    service 'sapgw-1' unknown / CPI-C error CM_PRODUCT_SPECIFIC_ERROR.</b>
    Thanks in Advance.
    Regards,
    Sandeep K.

    Hi Sandeep,
        My self , Sreedhar D, working eCATT using SAPGUI recording.
        i think ur problem is resolved. Can u help for the below issue.
          Scenario:       
           And i working on testing server which does not have any trasaction, i have to record the transaction using RFC connection to different machine.
           I did all the that process and able to connect  remote machine.
          i started doing the recoding in SAPGUI after creation of sys. Data container by specifying RFC connection.
            I recorded the script, but when i try to execute the same this attached error r coming.
           But i recorded the same using TCD(Recorded) using remote connection and able to sucessfully execute.
           One more thing also, we used write the script for reading the test data from Excel and pass as parameters using TCD(Recording).
    Below is the error
         Target sys ECATT_SAPTD120_400_E_0002
         Destination ECATT_SAPTD120_400_E_0002 RFC Error
          Waiting for ur response. Thanks in Adavance.
    Sreedhar d

  • Variables in a SAP GUI Script

    Hi All,                                                                                -
    Can somebody tell me, how can I use a variable instead of hardcoded value into a SAP GUI script?
    Because the recorded file is a vbs-file, I have tried to declare a variable as usual:
    Dim Count As Integer
    Count  = 58
    But when I try to execute the updated script, even without assigning the Count variable to any places from the script, an error occurs u2013 u2018expected end of statementu2019 (the same error also occurs if I use Count instead of 58). Actually I want to replace all occurrences of number 58 in the script below. Can anybody help me?
    Thanks,
    Svetlana
    If Not IsObject(application) Then
       Set SapGuiAuto  = GetObject("SAPGUI")
       Set application = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(connection) Then
       Set connection = application.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 application, "on"
    End If
    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell").contextMenu
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell").currentCellColumn = "DATA"
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell").contextMenu
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell/shellcont[1]/shell").modifyCell 0,"DATA","M_FORMOFADDR"
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[0]/shell").insertRows "58"
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[0]/shell").modifyCell 58,"PNAME","M_FORMOFADDR"
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[0]/shell").modifyCell 58,"PTYP","I"
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[0]/shell").setCurrentCell 58,"PTYP"
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[0]/shell").firstVisibleRow = 53
    session.findById("wnd[0]/usr/tabsTS_SCRIPT_EDITOR_0202/tabpECSC_ED/ssubTR_SCRIPT_REF1:SAPLECATT_MAIN:0402/cntlCC_ECSC_EDITOR/shellcont/shell/shellcont[0]/shell").pressEnter
    Edited by: Svetlana Balinova on Jul 21, 2009 3:12 PM
    Edited by: Svetlana Balinova on Jul 21, 2009 3:13 PM

    Hi Svetlana,
    if I have understood correctly, could it be that the following link you could use a bit:
    Referencing a variable in 'session findbyId' command (SAP GUI Scripting)
    Regards,
    ScriptMan

  • Quick SAP Script question New Page Print

    Quick SAP Script question
    I have added a new page to an existing SAP Script BUT only want it to print if a condition is true.
    I need to do this from within the form as the print program is SAP Std.
    Any idea how I can prevent the new page from printing?
    i.e. I need the form NOT to call the new page if the condition is false. Is there a way of forcing an exit or stop from with in the form?

    Hi,
    To trigger a new page, there is script ediotr command NEW-PAGE.
    so find where is that command is triggered and use the below code for trigger it on any specific condition....
    if &condition& = 'True'
    /*  NEW-PAGE
    elseif
    /: NEW-PAGE   
    endif
    so it means if condition is satisfied your new page will not work.. else it will...
    Hope you got it...
    Try this..
    Best luck..
    Regs,
    Lokesh.

  • Calling GUI Scripting from ABAP program

    Is it possible to call GUI Scripting from ABAP and thus to use GUI Scripting as an alternative to CALL TRANSACTION?
    Is the class CL_JAVA_SCRIPT suitable to access GUI Scripting engine? Accessing ABAP data object would work as well in this case as i think. What SAP Logon and WAS releases are required? Is the 6.20 release sufficient for this case?
    I would appreciate if somebody could post an example.

    Hi,
    CL_JAVA_SCRIPT has nothing to do with SAPGUI Scripting.
    Calling SAPGUI Scripting API from ABAP could be possible for programmes experienced with OLE automation calls from ABAP coding.
    The hardest thing will be, to access the scripting engine handle as an entry point. Once you have a handle in your abap session, any api function can be invoked.
    Best regards
    Jens
    BTW: SAP testtool eCATT does call SAPGUI-Scripting from ABAP.

  • AppleScript GUI scripting problem.

    Hi All,
    I've created a script that will automatically open new document in Indesign CS2. But when i run the script i'm getting system events error as "NSReceiverEvaluationScriptError: 4". I tried following the instruction given in forums but still couldn't figure out. Below is the script i wrote. Can any one tell where and what i'm missing.
    tell application "Adobe InDesign CS2" to activate
    tell application "System Events"
    tell process "Adobe InDesign CS2"
    tell menu bar 1
    tell menu bar item "File"
    tell menu "File"
    tell menu item "New"
    tell menu "New"
    click menu item "Document"
    end tell
    end tell
    end tell
    end tell
    end tell
    click button "Ok" of window 1
    end tell
    end tell
    This is the submenu of menu New. This might be the problem cos the below script works for for which i'm clicking the menu not sub menu
    tell application "Adobe InDesign CS2" to activate
    tell application "System Events"
    tell application process "Adobe InDesign CS2"
    tell menu bar 1
    tell menu bar item "Help"
    tell menu "Help"
    click menu item "Welcome Screen..."
    end tell
    end tell
    end tell
    end tell
    end tell
    My Mac version 10.4.10
    Any help would be appreciated.
    -Jacintha

    Using GUI scripting is the road to madness; it's for emergency use only.<br />Try:<br /><br />tell application "Adobe InDesign CS2"<br />make document<br />end tell<br /><br />-- <br />Shane Stanley <[email protected]>

  • Simple GUI script with a list

    Good day
    As my first Powershell project i'd like to write a script which will present to the user a GUI with a list of servers. The user then chooses a server and on click of the OK button connects to it with MSTSC. The window can look like this:
    Probably a script accomplishing a similar task already exists. Can you point it out? Also i'd like to learn more about developing specifically GUI scripts. Can you direct me to a source of information on that subject? A book maybe?
    Regards
    Kamil

    I know you want to learn how to build GUI, but what you asked for can actually be accomplished with just a few lines of code. The downside is you will not have any control over the layout.
    You can load the list of servers from CSV:
    $CSV = @"
    "Name","OperatingSystem","Description"
    "SERVER01","Windows Server 2008 R2","File Server"
    "SERVER02","Windows Server 2012 R2","Domain Controller"
    "SERVER03","Windows Server 2012","Print Server"
    $Servers = ConvertFrom-Csv $CSV
    $Servers | Out-GridView -Title "Select a server" -PassThru | Select Name |
    %{Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$($_.Name)"}
    Or you can get them directly from Active Directory:
    Get-ADComputer -Filter 'Name -like "SERVER*"' -Properties OperatingSystem, Description |
    Select Name, OperatingSystem, Description |
    Out-GridView -Title "Select a server" -PassThru | Select Name |
    %{Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$($_.Name)"}

  • Documentation on GUI scripting

    I am looking for some detailed documentation on GUI scripting. I am trying to figure out the click command so that I may use it in fireFox.
    Robert

    Chances are, your problem isn't with click because its options are very straightforward:
    click
    click (verb)cause the target process to behave as if the UI element were clicked (from Processes Suite)
    function syntax
    set theResult to click UI element ¬
    at list
    result
    UI element
    direct parameter optional UI element The UI element to be clicked.
    at optional list when sent to a "process" object, the { x, y } location at which to click, in global coordinates
    The problem is more likely to be how to work out the UI Element you want to click. Many applications make this less than obvious since it's often an object in a pane of a window and you need to know all the parts. If that is the case, get a copy of Prefab's UI Browser which does all the hard work of working out the UI element.

  • Scripting Question - Very Basic

    Hello, I'm using the trial version of InDesign and am wondering if because it's the trial version that I can't load custom scripts from Adobe?  I've downloaded and installed a Custom Calendar script [I can see the extracted files in/on my PC] but the app apparently doesn't see it.  Any help you can offer is greatly appreciated.  Thanks, 

    Thank you so much, you were spot on. 
    From: Peter Spier <[email protected]>
    To: Friar5 <[email protected]>
    Sent: Monday, December 12, 2011 3:18 PM
    Subject: Scripting Question - Very Basic
    Re: Scripting Question - Very Basic created by Peter Spier in InDesign - View the full discussion
    Have you put thew script in a location that InDesign uses for scripts? See How to install scripts in InDesign | InDesignSecrets
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4079869#4079869
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4079869#4079869. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in InDesign by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Executing SAP GUI Script From a Web Page

    I have an issue when trying to execute some javascript (sap gui script) from a webpage. 
    When the javascript is executed I get the message:
    automation server unable to create object. 
    However, this exact same javascript when placed in a text file and double-clicked executes just fine through the windows scripting host. 
    Does anyone have an example of gui script code executing from a webpage?  Or any ideas on why it isn't working from the webpage?  Both scenarios should be executing the code on the local machine through WSH.
    Below is the javascript as well as the webpage executing the javascript:
    SAPGUI SCRIPT
    if (typeof(application) == "undefined")
       sapgui      = GetObject("SAPGUI");
       application = sapgui.GetScriptingEngine;
    if (typeof(connection) == "undefined")
       connection = application.children(0);
    if (typeof(session) == "undefined")
       session = connection.children(0);
    if (typeof(WScript) != "undefined")
       WScript.connectObject(session, "on");
       WScript.connectObject(application, "on");
    session.findById("wnd[0]").maximize();
    session.findById("wnd[0]/tbar[0]/okcd").text = "/nzsd1067";
    session.findById("wnd[0]").sendVKey(0);
    session.findById("wnd[0]/usr/ctxtVBAK-KUNNR").text = "6343";
    session.findById("wnd[0]").sendVKey(0);
    WEBPAGE
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
         <head>
              <title></title>
              <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
              <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
              <! INPUT PARAMETER SETTINGS:
              To Push data to Siebel or SAP the appropriate
              field below must be set = TRUE.
              Pop_SAP
              Pop_Siebel
              SIEBEL INPUT PARAMETER: When
              Pushing data to a Siebel screen the Query_Type should be set based on the type
              of lookup that is requested.
              Query_Type = 'SAP' -presents a screen based on a customer SAP Id.
              Query_Type = 'SR' -presents a screen based on a Service Request.
              Query_Type = '' or null -presents a search screen to locate the proper contact in Siebel
              APP_SAP_ID -SAP customer Id
              APP_SR_NUM -Siebel Service Request Number
              >
    <SCRIPT LANGUAGE="VBScript">
    Sub LoadContact()
            'Siebel Application Object
            Dim siebApp 'As SIEBELHTMLLib.ISiebelHTMLApplication
            Dim siebSvcs 'As SIEBELHTMLLib.ISiebelService
            Dim siebOutputPropSet 'As SIEBELHTMLLib.ISiebelPropertySet
            Dim siebInputPropSet 'As SIEBELHTMLLib.ISiebelPropertySet
            Dim bool 'As Boolean
            Dim errCode 'As Integer
            Dim errText 'As String
            Dim QueryType 'As String
         Dim PopSAP 'As String
         PopSiebel = "TRUE"
         If PopSiebel = "TRUE" Then
              QueryType = "SAP"
              If QueryType = "null" Then
                   QueryType = ""
              End If
                 'Create The SiebelHTML Object      
                 set siebApp = CreateObject("SiebelHTML.SiebelHTMLApplication.1")  
                 If Not siebApp Is Nothing Then
                     'Create A New Property Set
                     set siebInputPropSet = siebApp.NewPropertySet
                     set siebOutputPropSet = siebApp.NewPropertySet
                     If Not siebInputPropSet Is Nothing Then
                         siebInputPropSet.SetProperty "ANI", "9738986011"
                         siebInputPropSet.SetProperty "SAP_ID", "0000516616"
                         siebInputPropSet.SetProperty "SR_NUM", "null"
                         siebInputPropSet.SetProperty "Interaction_ID", "168608840053"
                         siebInputPropSet.SetProperty "Query_Type", QueryType
                     Else
                         errCode = siebApp.GetLastErrCode
                         errText = siebApp.GetLastErrText
                             MsgBox "Could not Create Siebel Property Set: " & errCode & "::" & errText
                     End If
                     'Get A Siebel Service
                     set siebSvcs = siebApp.GetService ("TAWBS")
                     If Not siebSvcs Is Nothing Then
                         siebSvcs.InvokeMethod "TAWPresentAccount", siebInputPropSet, siebOutputPropSet
                  Else
                         errCode = siebApp.GetLastErrCode
                         errText = siebApp.GetLastErrText
                   MsgBox "Could not Get Siebel Service: " & errCode & "::" & errText
                         End If
                     set siebApp = Nothing
                 End If
                 set siebInputPropSet = Nothing
                 set siebOutputPropSet = Nothing
                 set siebSvcs = Nothing
         End If 
    End Sub
    </SCRIPT>
    <SCRIPT LANGUAGE="javascript">
    function loadSAP()
         if (typeof(application) == "undefined")
              sapgui      = GetObject("SAPGUI");
              application = sapgui.GetScriptingEngine;
         if (typeof(connection) == "undefined")
              connection = application.children(0);
         if (typeof(session) == "undefined")
              session = connection.children(0);
         if (typeof(WScript) != "undefined")
              WScript.connectObject(session, "on");
              WScript.connectObject(application, "on");
         session.findById("wnd[0]").maximize();
         session.findById("wnd[0]/tbar[0]/okcd").text = "/nzsd1067";
         session.findById("wnd[0]").sendVKey(0);
         session.findById("wnd[0]/usr/ctxtVBAK-KUNNR").text = "0000516616";
         session.findById("wnd[0]").sendVKey(0);
    } // end
    </SCRIPT>
    </head>
         <body onload="loadSAP()">
              <H3><FONT face="Arial" size="5">Raytheon Integration Screen</FONT></H3>
              <HR style="WIDTH: 882px; HEIGHT: 8px" color="#3366cc" SIZE="8">
              <form id="ValidForm" onsubmit="LoadContact(); return false;" language="jscript">
                   <FONT face="Arial">Load Siebel Screen</FONT> <! <input name="Text1" TYPE="TEXT"
                   SIZE="10" ID="Text1"> <input name="Submit" TYPE="submit" VALUE="Submit" ID="Submit1">
              </form>
              <form id="Form1" onsubmit="loadSAP(); return false;" language="javascript">
                   <FONT face="Arial">Load SAP Screen</FONT>    <! <input
                   name="Text2" TYPE="TEXT" SIZE="10" ID="Text2"> <input name="Submit" TYPE="submit" VALUE="Submit" ID="Submit2">
              </form>
         </body>
    </html>

    Hi Bernd,
    the following code works in VBS. If you run saplogon.exe you'll get a message box saying '/app'.
    Set Wrp = CreateObject ("SapROTWr.SapROTWrapper")
    Set SapGui = Wrp.GetROTEntry ("SAPGUI")
    Set application = sapgui.GetScriptingEngine
    MsgBox application.id
    I haven't tried it on a web page, but I don't see why it shouldn't work there. Ok, maybe the MsgBox is command is not available.
    Best regards,
    Christian

Maybe you are looking for