Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Monday, July 7, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Validate script runs twice
Sarah Peterson
Posts: 37
 
Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Nov 06 11:04 AM
fiogf49gjkf0d
I have a custom form that gets called from a right-click menu option on a datagrid tab. The validate script appears to run twice and I cannot figure out why. There is only one field on this custom form and the validation is a simple If statement. We have run into this issue on another form as well (with just simple If...statements) and have not been able to resolve the issue.

The validation for this form is:

Function AXFormValidate(Sender)
if txtCustomerID.Text = "" then
MsgBox "You must select or enter a Customer ID.", 0, "Invalid Customer ID"
txtCustomerID.setfocus
AXFormValidate = false
exit function
end if
End Function

Any suggestions?
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Nov 06 5:10 PM
fiogf49gjkf0d
You don't need the exit function call. It's redundant. I believe the problem is AXFormValidate never evaluates to true. It may never default to true, so it's generally best not to leave that up to chance.

If that's not it, the only time I've ever had it fire twice is when I put an AXFormValidate call in my OK button's OnClick event while having OnValidate set. OnClick would fire, evaluating the form before I would call Form.ModalResult. The problem was SalesLogix's built in handling for Forms would kick off OnValidate, so I'd have to turn it off or risk it firing twice. It's not a problem when the form is valid because no MsgBox pops up but it'd still be firing twice.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 06 Nov 06 6:46 PM
fiogf49gjkf0d
Out of curiosity, what does the code look like that triggers the form to close? Are you closing it in code, or is it happening as the result of a button click with ModalResult=mrOK?
[Reply][Quote]
Sarah Peterson
Posts: 37
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Nov 06 8:50 AM
fiogf49gjkf0d
I tried defaulting the AXFormValidate = true as the first line of code in the validate function. That did not work.

Here is the code that I think you are looking for Ryan. If not, let me know! Thanks...

Sub Button1Click(Sender)
application.GlobalInfo.Add "BranchMoveCustID", txtCustomerID.Text

MoveBranches.ModalResult = mrOK
Application.BasicFunctions.InvokeSetResult "mrOK"
End Sub

Sub Button2Click(Sender)
MoveBranches.ModalResult = mrCancel
Application.BasicFunctions.InvokeSetResult "mrCancel"
End Sub
[Reply][Quote]
Jeremy Brayton
Posts: 491
Top 10 forum poster: 491 posts
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Nov 06 1:54 PM
fiogf49gjkf0d
Here's my typical AXFormValidate, which I pretty much use on every single form (give or take it's contents):

Function AXFormValidate(Sender)
dim stringMissing
dim booleanIsValid
dim booleanResult
dim integerResult
On Error Resume Next
booleanResult = false
integerResult = 0
booleanIsValid = true
if (pickListType.Text = "") then
if (stringMissing = "") then
stringMissing = "Type"
else
stringMissing = stringMissing & ", Type"
end if
booleanIsValid = false
end if
if (pickListStatus.Text = "") then
if (stringMissing = "") then
stringMissing = "Status"
else
stringMissing = stringMissing & ", Status"
end if
booleanIsValid = false
end if
if (not (booleanIsValid)) then
integerResult = MsgBox(Application.Translator.Localize("The following items must be filled in: " & vbCRLF & stringMissing), vbYes, Application.Translator.Localize("Validation"))
booleanResult = false
else
booleanResult = true
end if
AXFormValidate = booleanResult
ErrorCheck(Application.Translator.Localize("AXFormValidate:"))
On Error Goto 0
End Function

Here's a typical OK button OnClick event:

Sub buttonOKClick(Sender)
dim booleanResult
On Error Resume Next
booleanResult = AXFormValidate(oAXForm)
if (booleanResult) then
oAXForm.ModalResult = mrOk
Application.BasicFunctions.InvokeSetResult "mrOk"
else
oAXForm.ModalResult = mrNone
Application.BasicFunctions.InvokeSetResult "mrNone"
end if
ErrorCheck(Application.Translator.Localize("buttonOKClick:"))
On Error Goto 0
End Sub

I ONLY use buttonOKClick on Manage Forms. Data Form OK and Cancel buttons work nicely as-is, and there is absolutely no need to override them with custom code except in special circumstances. Your case almost presents such a circumstance but I would place the GlobalInfo.Add at the end of your AXFormValidate routine, otherwise it's a wasteful call if the form hasn't been validated first.

To use this technique, turn off the OnValidate event. The code calls AXFormValidate BEFORE calling Form.ModalResult. If you were to blindly set Form.ModalResult on a Manage Form, it would close the form regardless of AXFormValidate's return. This is my poor man's way of making manage forms behave like data forms.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Nov 06 9:17 AM
fiogf49gjkf0d
Is "MoveBranches" the name of the form, or the name of some other control on the form, like a button?
[Reply][Quote]
Sarah Peterson
Posts: 37
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Nov 06 9:20 AM
fiogf49gjkf0d
Ryan, 'MoveBranches' is the name of the Pop-up form. It requires the user to enter in a customer number to move the branches to.
[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Validate script runs twiceYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Jun 10 8:46 AM
Here's how I remember all of this:

AXFormValidate is called by mrOK modal buttons.

AXFormValidate is NOT called by mrNone or mrCancel buttons.

AXFormValidate is NOT called when hitting the ESC key or the X in the upper right hand window corner.

If you do NOT have an AXFormValidate event and script, clicking on an mrOK button will fire your script, save any databound data on a data entry form, and close the form.

If you HAVE an AxformValidate event and script, you pass it input parameters via form controls, the form itself, and global variables.

The AXFormValidate logic should process these 'input' parameters and come up with an answer: Keep the form Open (don't save the data, don't close the form), or Close the Form (save the data, close the form, mrOK is the modality).

If fires AFTER the onButtonClick event for an mrOK modal button.

It does NOT fire after you've run code somewhere that does an
Application.BasicFunctions.CloseCurrentView False

If you have several mrOK buttons.....the AXFormValidate fires off on any of the clicked upon buttons AFTER it runs the script for the clicked upon button ONLY. (Duh).

don't call AXFormValidate or use it as a function (when you use AXFormValidate as a function do you know what SENDER really is??? because it needs to be the Form). The FORM does that automagically as a form level event handler.

Declare a global variable: OKToCloseForm
Set it to False when the form opens.

When controls change or an mrOK button is pressed evaluate what you have to and come up with an answer: OKToCloseForm = True or False...and possibly a message box to your user.

when the AXFormValidate is triggered by the form:
Sub AXFormValidate (Sender the form itself)
AXFormValidate = False
IF OKToCloseForm Then AXFormValidate = True
End Sub
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 7/7/2025 5:09:45 PM