Validation on Submit in Script

How do I convert the @Command code below which validates field completion on submission of a form into the script below it.

@If(field = "";
    @Do(@Prompt([Ok];"Missing Data";"You must reply to the question");
@Command ([EditGotoField];"field"); @Return("")); "");

Sub Initialize
      Dim ws As New NotesUIWorkspace()
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim db As NotesDatabase
      Dim noteid As String
      
      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.Document
      Set db = doc.ParentDatabase
      Call uidoc.Save()
      noteid = doc.NoteID
      Call uidoc.Close(True)
      Set doc = db.GetDocumentByID(noteid)
      
      Dim emaildoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Set emaildoc = doc.ParentDatabase.CreateDocument()
      emaildoc.Form = "submit_tracer"
      emaildoc.SendTo = doc.Author
      emaildoc.CopyTo = doc.gatekeeper
      Call emaildoc.Send(True)
      
      doc.submit_date = Today
      Call doc.Save(True,True)
End Sub
jforget1Asked:
Who is Participating?
 
madheeswarConnect With a Mentor Commented:
In the Query Save:
dim curdoc as notesdocument
set curdoc=Source.document

If curdoc.fieldname(0)="" then
msgbox "Please enter value"
call source.gotofield("fieldname")
continue=false
exit sub
end if
0
 
SysExpertCommented:
Should be put in the QuerySave

      Set w = New notesuiworkspace    
      
      Set src = w.currentdocument  ' UI Doc
              If Trim(src.fieldgettext("fieldname" )="" Then
                  msgbox "missing Data, please fill in required field "
               Call src.GotoField("fieldname")    
 
             end if

----

I hope this helps !
0
 
jforget1Author Commented:
Would it just be duplication the If to check more than one field?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
qwaleteeCommented:
You probably want a function taht you can call, so it looks like this

Function ValidEntry(fieldName as string, source as notesUiDocument )
  If source.fieldGetText(fieldName) = "" then
    MsgBox "You must enter a value for " & fieldName
    source.GotoField fieldName
  Else
    validEntry = true
  End If
End Function

Sub QuerySave(Source as NotesUiDocument ... continue)
  fieldNames = Split("field,field2,field3")
  ForAll fieldName in fieldNames
    If Not ValidEntry Then
      continue = false
      Exit Sub
    End If
  End Forall

  Call source.Save()
    set doc = source.document
     
      Dim emaildoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Set emaildoc = doc.ParentDatabase.CreateDocument()
      emaildoc.Form = "submit_tracer"
      emaildoc.SendTo = doc.Author
      emaildoc.CopyTo = doc.gatekeeper
      Call emaildoc.Send(True)
     
      doc.submit_date = Today

End Sub
0
 
jforget1Author Commented:
madheeswar,

that code worked great for what I need. Do you know if this can be done as an either or, I have an app_name field and a new_app_name field. I want to validate that at least one of these has data. I can't do the app_name by itself, because if they are entering in the new_app_name field, they would get prompted to enter in the other field.
0
 
madheeswarCommented:
that's simple...
If curdoc.fieldname1(0) ="" or curdoc.fieldname2(0)="" then
replace for IF......
0
 
qwaleteeCommented:
Function ValidEntry(fieldName as string, source as notesUiDocument )
  If source.fieldGetText(fieldName) <> "" then
    validEntry = true
  End If
End Function

Sub QuerySave(Source as NotesUiDocument ... continue)
  fieldNames = Split("field,field2,field3")
  Dim foundAnyValid As Boolean
  foundAnyValid = flase
  ForAll fieldName in fieldNames
    If ValidEntry(fieldName,source) Then
      foundAnyValid = True
      Exit Forall
    End If
  End Forall
  If Not foundAnyValid Then
    MsgBox "You must enter a value for at least one of the following " & fieldNames
    source.GotoField fieldName
  End If

  Call source.Save()
    set doc = source.document
      Dim emaildoc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Set emaildoc = doc.ParentDatabase.CreateDocument()
      emaildoc.Form = "submit_tracer"
      emaildoc.SendTo = doc.Author
      emaildoc.CopyTo = doc.gatekeeper
      Call emaildoc.Send(True)
     
      doc.submit_date = Today

End Sub
0
 
jforget1Author Commented:
Appreciate all the help here, was at a Lotus Script class and just getting caught up. Class was great and really gave an understanding of how things are tied together in LS, hopefully the number of questions I need to post will be less now with this new knowledge.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.