Skip to content

Instantly share code, notes, and snippets.

@gsherman
Created May 30, 2012 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsherman/2839349 to your computer and use it in GitHub Desktop.
Save gsherman/2839349 to your computer and use it in GitHub Desktop.
initialize_app, handle clarify url on command line
Declare Sub ProcessCommandLineArgs()
Declare Function lstrcpyn_long_string Lib "kernel32" Alias "lstrcpynA" (ByVal DestString As String, ByVal SourcePointer As Long, ByVal MaxLen As Long) As Long
Declare Function lstrlen_long Lib "kernel32" Alias "lstrlenA" (ByVal SourcePointer As Long) As Long
Declare Function GetCommandLine_long Lib "kernel32" Alias "GetCommandLineA" () As Long
Declare Sub handle_clarify_url(url as String)
Declare Function parse_string(str_input as String, str_delim as String, _
int_count as Integer, lst_words as List) as Integer
Public Sub initialize_app()
Call ProcessCommandLineArgs()
End Sub
Sub ProcessCommandLineArgs()
'Process any clarify URLS that were passed in on the command line
'(such as clarify://case/12345)
dim cmdLine as String
dim url as String
dim result as integer
dim num as Integer
dim listWords as new List
dim pos as integer
' This should have worked, but didnt. bummer.
'cmdLine = Command$
'but this does (using win32 calls):
cmdLine = GetCommandLine()
pos = InStr(cmdLine, "clarify://")
if pos > 0 Then
url = Mid$(cmdLine, pos)
Call handle_clarify_url(url)
End If
End Sub
Function GetCommandLine() As String
'Get a pointer to process commandline as Long
Dim ptrCommandLine As Long
ptrCommandLine = GetCommandLine_long
If ptrCommandLine > 0 Then 'GetCommandLine ok
Dim Buffer As String, BufferLength As Long
'Get a length of the command line using Long pointer
'Returns the length without the zero terminating char
BufferLength = lstrlen_long(ptrCommandLine)
If BufferLength > 0 Then
'Allocate a space for the command line
Buffer = Space(BufferLength + 1)
'Copy the command line to a buffer using Long + String pointers.
ptrCommandLine = lstrcpyn_long_string(Buffer, ptrCommandLine, BufferLength + 1)
'The copy SHOULD be OK. Zero means some error, not enough of space
If ptrCommandLine > 0 Then 'lstrcpyn
'Remove the zero terminator from the copied string
Dim PosZero As Long
PosZero = InStr(Buffer, Chr$(0))
If PosZero > 0 Then Buffer = Left(Buffer, PosZero - 1)
GetCommandLine = Buffer
End If 'If ptrCommandLine > 0 Then 'lstrcpyn
End If 'If BufferLength > 0 Then
End If 'If ptrCommandLine > 0 Then 'GetCommandLine ok
End Function
Sub handle_clarify_url(url as String)
dim result as integer
dim num as Integer
dim listWords as new List
dim id as String
dim objectType as String
dim winName as String
winName = "ClarifyCRM"
On Error Resume Next
AppActivate winName
On Error Goto 0
result = parse_string(url, "/", num, listWords)
objectType = listWords.ItemByIndex(2)
id = listWords.ItemByIndex(3)
if objectType = "case" Then
if id = "new" then
App.NewCase
else
show_case id
end if
end if
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Show an Existing Case
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub show_case(case_id As String)
Dim t_ret As New BulkRetrieve ' Structure to query the DB
Dim case_list As List ' List of returned cases
Dim case_rec As Record ' One returned case
' Query for the case
' Get the results
t_ret.SimpleQuery 0, "case"
t_ret.AppendFilter 0, "id_number", cbEqual, case_id
t_ret.RetrieveRecords
Set case_list = t_ret.GetRecordList(0)
' If case not found, error message
' Else, post the case
If case_list.Count = 0 Then
App.MsgBox "Customer keyed in case " + case_id + ", but that case is not found in the database."
Else
Set case_rec = case_list.ItemByIndex(0)
App.ShowCase case_rec
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment