Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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
0
jforget1
Asked:
jforget1
  • 3
  • 2
  • 2
  • +1
1 Solution
 
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
 
madheeswarCommented:
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
 
jforget1Author Commented:
Would it just be duplication the If to check more than one field?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now