
In SalesLogix, you have the ability to invoke a form as a main view object. This is handy for a number of reasons, but there appears to be one major drawback. When invoking a form as a main view object, sometimes the form can take an inordinate amount of time to open, giving the sense that the system has hung.
Instead of opening a main view object, you can avoid the delay in opening the form by simply invoking the new form, and then using global variables to pass any necessary information back to the invoked form.
This sample code is for an account tab which calls an edit view containing a single picklist control, which sets the current Account Type value.
Using a main view object, a recordset is opened, getting the current type value, which is then passed on to the main view form. On a modal result of “mrOK”, the recordset is updated with whatever value was selected in the edit view. The mainview itself contains no code; View defaults and dataupdates are performed by the originating script.
Sub cmdMainViewClick(Sender)
Dim objRS
Dim objMainView, objDetail
Set objRS = Application.CreateObject(“ADODB.Recordset”)
With objRS
.LockType = adLockOptimistic
.Open “Select type from account where accountid = ‘” & Application.BasicFunctions.CurrentAccountID & “‘”, Application.GetNewConnection
Set objMainView = Application.MainViews.Add(“Personal:Set Account Type”, 0, False)
Set objDetail = objMainView.DetailsView
objMainView.BorderStyle = 3
objMainView.Caption = Application.Translator.Localize(“Set Account Type”)
objDetail.pklAccountType.Text = .Fields(“Type”).Value & “”
If objMainView.ShowModal = mrOK Then
.Fields(“Type”).Value = objDetail.pklAccountType.Text
.Update
End If
Set objDetail = Nothing
Set objMainView = Nothing
.Close
End With
Set objRS = Nothing
End Sub
I order to launch the form, I simply set any parameters I need to global variables, then invoke the form:
Sub cmdDoInvokeClick(Sender)
Application.BasicFunctions.GlobalInfoSet “gAccountID”, Application.BasicFunctions.CurrentAccountID
Application.BasicFunctions.DoInvoke “View”, “Personal:Set Account Type”
End Sub
On the WhenOpen event of the form, I set any initial values I need on the form using the globals I set before invoking the edit view.
Sub AXFormOpen(Sender)
If Application.BasicFunctions.GlobalInfoExists(“gAccountID”) Then
strAccountID = Application.BasicFunctions.GlobalInfoFor(“gAccountID”)
Form.Caption = “Set Account Type”
Form.ModalResult = mrNone
pklAccountType.Text = GetField(“TYPE”, “ACCOUNT”, “ACCOUNTID = ‘” & strAccountID & “‘”)
end If
End Sub
On the whenclick event of the ok button, I update values as necessary and close the view:
Sub cmdOKClick(Sender)
Dim objSLX
If Application.BasicFunctions.GlobalInfoExists(“gAccountID”) Then
Set objSLX = New SLX_DB
objSLX.ExecuteSql “update account set type = ‘” & pklAccountType.Text & “‘ where accountid = ‘” & strAccountID & “‘”
Application.BasicFunctions.GlobalInfoClear “gAccountID”
Form.ModalResult = mrOK
End If
End Sub
As a best practice, using the DoInvoke function isn’t ideal. For now though, it seems to be the most effective way to get around that pesky delay when opening mainview objects.
(The bundle contains the views and code as outlined above)
Have you ever heard anything to imply that they are aware of the issue? It’d be great if that was somthing that got fixed at some point.