AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Effectively use sub GUIs to prompt user for input.

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
samhnky



Joined: 29 Sep 2009
Posts: 75

PostPosted: Tue Nov 24, 2009 3:15 pm    Post subject: Effectively use sub GUIs to prompt user for input. Reply with quote

I'm writing a collection of scripts for my Service Desk, and have run into a problem dealing with sub GUIs... Specifically when calling the sub GUI in the middle of an active "automation" script. For example the script below is a sub routine in my AHK file (i.e. called by a GoSub command) This script has to gather information about my caller from the Remedy ticket. (The TabTo() function navigates the ticket using If,Else statements and an INI file for the tickets Tab order... Yes I've tried and can find no other way to navigate the tickets by keyboard Sad ) After gathering the customer information from the ticket it then generates an email to the customer, using their email address, the ticket number and the description of the ticket, and then it updates the ticket recording the agents attempt to contact the customer. The issue with this script is that this is the 2nd day contact so the tickets description already has recorded tags for the first days contact. So when creating the email I have the script prompt the agent to fix the Ticket Description by removing Day 1 tags before it inserts it into the email. (I also re-use this variable to update the ticket description with the 2 day tags.) I have this part working, although I believe there is probably a better way. The next issue comes when trying to automate the attachment of the generated email to the ticket. Our system has 5 places to attach files so I need to prompt the user for file position to attach the email too. The problem I'm having is that the script continues running even with this prompt on the screen... I've tried using Sub routines with IF statements and while loops to verify when a variable had changed before continuing through the script, I've also tried using functions... I keep having the problem that the scrip will not waite for the sub routine, or function to do its job... I also believe there is an easier way to create my OK buttons, and I know I'm not terminating my sub GUI correctly... when I use "ExitApp" it closes the Sub GUI and the Root GUI, when I use the "GUI, Destroy" I run into problems with getting the variables saved before the GUI is destroyed... Mad Very frustrating...

Code:
t2_day2_HK:
GoSub, COB_Parse
If A_DD = %cob_day%
  {
  MsgBox,0,Error: COB Date,ERROR: COB Date = Todays Date`r`nPlease Select a COB Date
  Return
  }
SetTitleMatchMode 2
WinWait, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
IfWinNotActive, Remedy User - [CITS Service Management (Modify)], CITS Service Managem, WinActivate, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
WinWaitActive, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
ClipCurrent = %ClipBoardAll%
ClipBoard = ;
Sleep, 350
Send, +^{HOME}
Sleep, 100
Send, {TAB %case_id%}
Send, +{HOME}^c
ClipWait ;
cobticket = %ClipBoard%
Clipboard = ;
Sleep, 350
TabTo(email_address, case_id)
Sleep, 100
Send, ^{END}+{HOME}^c
ClipWait ;
cobemail = %ClipBoard%
ClipBoard = ;
Sleep, 350
TabTo(short_description, email_address)
Sleep, 100
Send, +{UP}+{HOME}^c
ClipWait ;
cobshortDis = %ClipBoard%
ClipBoard = ;
Sleep, 350
Run mailto:%cobemail%&subject=Ticket due to close: %cobticket%
WinWait, Ticket due to close: %cobticket%
Sleep, 1000
ClipBoard = ServiceDesk Ticket-Updates
ClipWait ;
Send, +{TAB 4}^v
Sleep, 300
ClipBoard = A Service Desk agent was unable to reach you at phone number provided in the ticket. This is the second attempt to contact you regarding ticket number
ClipWait ;
Send, {TAB 5}^a{DEL}
Send ^v^b{SPACE}<
Sleep, 300
ClipBoard = %cobticket%>
ClipWait ;
Send ^v^b{SPACE}
Sleep, 300
ClipBoard = The description for this ticket is:
ClipWait ;
Send ^v^b{SPACE}<
Sleep, 300
Clipboard = ;
GoSub, Format_Short_Description
ClipWait ;
WinActivate, Ticket due to close: %cobticket%
Send %COB_Short_Description%>{ENTER}{ENTER}
ClipBoard = Your ticket will be CLOSED if there is no response by close of business tomorrow <%cob_month%/%cob_day%>
ClipWait,
Send, ^v^b{SPACE}
Sleep, 300
Clipboard = ;
Clipboard = If you are still experiencing a problem or have any questions, please contact the Service Desk immediately at xxx-xxx-xxxx. We look forward to assisting you.
ClipWait ;
Send ^v^b{ENTER}{ENTER}%Agent_Initials%^b{SPACE}
Sleep, 300
ClipBoard = | `r`nService Desk Support Specialist II`r`nIT Services`r`nPhone: %Service_Desk_Phonenum% Fax: %Service_Desk_faxnum%`r`n%Service_Desk_homepage%
ClipWait ;
Send ^v
Sleep, 300
Send, !f
Sleep, 100
Send, a
WinWait, Save As,
;IfWinNotActive, Save As, , WinActivate, Save As,
WinWaitActive, Save As,
Sleep, 300
ClipBoard = %Stored_Email%Ticket due to close
ClipWait ;
Send ^v{TAB}oo{ENTER}{ENTER}
WinWait, Microsoft Office Outlook,
IfWinNotActive, Microsoft Office Outlook, , WinActivate, Microsoft Office Outlook,
WinWaitActive, Microsoft Office Outlook,
Send, {LEFT}{ENTER}
WinWait, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
IfWinNotActive, Remedy User - [CITS Service Management (Modify)], CITS Service Managem, WinActivate, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
WinWaitActive, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
Sleep, 350
ClipBoard = <ve %A_MM%/%A_DD% *COB %cob_month%/%cob_day%* %Agent_Initials% %COB_Short_Description%
Send {DEL}^v
TabTo(attachment, short_description)
attachment_file = 0
Attach_Email_To_Ticket()
WinActivate, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
WinWait, Remedy User - [CITS Service Management (Modify)], CITS Service Managem
If attachment_file > 1
  {
  Send, {DOWN %attachment_file%}
  }
If attachment_file < 5
  {
  Send, {UP}
  }
Send {APPSKEY}a
Sleep, 300
Send, %Stored_Email%Ticket due to close.msg{ENTER}
TabTo(worklog, attachment)
Send, %day2_work_log_entry%
TabTo(timespent, worklog)
Send, {BACKSPACE}5
TabTo(assignee, timespent)
Send, +{HOME}
Send, %Remedy_Name%
Sleep, 500
ClipBoard = %ClipCurrent%
COB_ticket_finished = 1
Return

COB_Parse:
GuiControlGet, Selected_Date ;This is from the "root" GUI Month Calendar display
Loop, parse, Selected_Date
{
date%A_index% = %A_LoopField%
}
cob_month = %date5%%date6%
cob_day = %date7%%date8%
return

TabTo(going_to, comeing_from)
{
if (going_to > comeing_from){
tabnum := going_to - comeing_from
  Send, {TAB %tabnum%}
  }
else{
tabnum := comeing_from - going_to
  Send, +{TAB %tabnum%}
  }
}

Format_Short_Description:
Gui 3:Default
Gui, Add, Text, x10 y10 w200 h30, Please Remove All Tier II Tags
Gui, Add, Edit, x10 y40 w200 h30 vCOB_Short_Description, %cobshortDis% ; So the agent can remove Tier II tags
Gui, Add, Button, x220 y40 w50 h30 gSave_COB_Short_Description, OK ; Calls subrouting to process this GUI.
Gui, Show, h80 w280, %program_title% Settings
Gui, +AlwaysOnTop -SysMenu +Owner
Return

Save_COB_Short_Description:
GuiControlGet, COB_Short_Description ;Assigns text in the GUI edit field COB_Short_Description to this variable.
Sleep, 500 ; A (ABC are to keep the sub GUI open until the variable data is set)
Clipboard = 1 ;B
ClipWait, ; C
Gui, Destroy ; Only way I've found to get rid of a Sub GUI without closing the Root GUI, and be able to reuse the Sub GUI within the scrip (i.e. my Root Gui will "never" be closed)
Return

Attach_Email_To_Ticket() ;I've tried doing this as a GoSub and now as a Function
{
Gui 5:Default
Gui, Add, Text, x10 y10 w200 h30, Please Type the number for the File Attachment (1-5)
global attachment_file
Gui, Add, DropDownList, x10 y40 w65 h45 r5 vattachment_file, 1|2|3|4|5
Gui, Add, Button, x220 y40 w50 h30, OK
Gui, Show, h80 w280, %program_title% Attachment File #:
Gui, +AlwaysOnTop -SysMenu +Owner
Return

5ButtonOK:
GuiControlGet, attachment_file
Sleep, 500
Clipboard = 1
ClipWait,
Exitapp ; Closes my program completely, not just this sub GUI.
}


I realize that this code will not run outside my environment, so troubleshooting it is not really possible; however, I'm hoping some experienced AHK programmers have either had similar problems and found a good solution, or maybe there is a "preset" way for doing this that I'm overlooking... I know I could use the InputBox for the first prompt and not mess with the GUI there at all, but I really want to use the drop down box in the second GUI, which I don't think there is an "innputbox" command line for.

Please let me know if you need more information or code with more comments.

Thank you,
Sam
Back to top
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Tue Nov 24, 2009 3:47 pm    Post subject: Reply with quote

I have read through your question/issue several times and cannot find a good 'starting place' as to what is wrong.


Could you 'simplify' your problem, maybe into bullet points. You give a LOT of information and go between it working and not working several times.

Maybe:
GUI1 needs X
GUI2 has Y
GUI2 doesnt do Z with GUI1

While the detail is always helpful, it is detracting from your problem.



That said, your code isn't bad. We have a similar ticketing system, I may be able to edit/cut/copy/paste and play around, but it looks strait forward. You could possibly replace some keyboard commands with blockinputs and mouseclicks, but that doesn't offer a real benifit.
Back to top
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 549
Location: Berlin / Germany

PostPosted: Tue Nov 24, 2009 4:00 pm    Post subject: Reply with quote

As an example:
Code:
Attach_Email_To_Ticket() ;I've tried doing this as a GoSub and now as a Function
{
global attachment_file
Gui 5:Default
Gui, Add, Text, x10 y10 w200 h30, Please Type the number for the File Attachment (1-5)
Gui, Add, DropDownList, x10 y40 w65 h45 r5 vattachment_file, 1|2|3|4|5
Gui, Add, Button, x220 y40 w50 h30, OK
Gui, Show, h80 w280, %program_title% Attachment File #:
Gui, +AlwaysOnTop -SysMenu +Owner
Gui, +LastFound   ; set the Last Found Window
WinWaitActive     ; "wait" until Gui5 is active
WinWaitClose      ; wait until Gui5 is closed (destroyed)
Return

5ButtonOK:
GuiControlGet, attachment_file
Sleep, 500
Clipboard = 1
ClipWait,
; ...
; ...
Gui, Destroy      ; destroy Gui5
Return
; Exitapp ; Closes my program completely, not just this sub GUI.
}

_________________
nick Wink
Back to top
View user's profile Send private message
samhnky



Joined: 29 Sep 2009
Posts: 75

PostPosted: Tue Nov 24, 2009 4:58 pm    Post subject: Reply with quote

Carcophan wrote:
I have read through your question/issue several times and cannot find a good 'starting place' as to what is wrong.


Could you 'simplify' your problem, maybe into bullet points. You give a LOT of information and go between it working and not working several times.

I'll try...


  • Good technique to pause a script waiting for GUI Input from user. (Not using Inputbox, but acutal GUI commands to draw a new GUI window.)
  • Best way to create, close, and capture variables from a sub GUI without closing "root" GUI, and guarantee that the paused script continues with captured variables
Back to top
View user's profile Send private message
samhnky



Joined: 29 Sep 2009
Posts: 75

PostPosted: Tue Nov 24, 2009 5:55 pm    Post subject: Reply with quote

nick wrote:
As an example:
Code:
Attach_Email_To_Ticket() ;I've tried doing this as a GoSub and now as a Function
{
global attachment_file
Gui 5:Default
Gui, Add, Text, x10 y10 w200 h30, Please Type the number for the File Attachment (1-5)
Gui, Add, DropDownList, x10 y40 w65 h45 r5 vattachment_file, 1|2|3|4|5
Gui, Add, Button, x220 y40 w50 h30, OK
Gui, Show, h80 w280, %program_title% Attachment File #:
Gui, +AlwaysOnTop -SysMenu +Owner
Gui, +LastFound   ; set the Last Found Window
WinWaitActive     ; "wait" until Gui5 is active
WinWaitClose      ; wait until Gui5 is closed (destroyed)
Return

5ButtonOK:
GuiControlGet, attachment_file
Sleep, 500
Clipboard = 1
ClipWait,
; ...
; ...
Gui, Destroy      ; destroy Gui5
Return
; Exitapp ; Closes my program completely, not just this sub GUI.
}


Looks like this took care of the problem... I'm not even using any If/Else , Wile loops, or GoSub Loops to hold the script in place... Thank you.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group