How to validade an attachment in a doc before we save it!

Hi fellows,

I’m having some problem to accomplish one of my customer functional requiriment.

FUNC REQ #28: The form should be only saved if the user have already attached the documentation of the project.

SOLUTION: In the form i created a rich text lite field named attachDocs and in there i have to manipulate it on QuerySave action in Lotus Script to validate if user har or not attached the docs…

Can anyone help me how to manipulate rich text light itens before documents got save. If the documents is save, the manipulations is ok , but when not, it isn’t.

Tks in advance,

Subject: RE: How to validade an attachment in a doc before we save it!!!

You must call NotesUIDocument.Refresh(true). Use On Error, since this method will throw an error if field input validations fail.

Subject: How to validade an attachment in a doc before we save it!!!

I had a similar request, and used the following.It’s a bit crude, but it works OK for me, and is just a suggestion.

  1. Rich Text Lite field is called LOVReqTemplate

  2. Second tab is allowing only attachments

  3. This field is the last one the first user will fill in (I am lucky in this respect)

  4. I have the following formula in onSubmit event:

Sub Onsubmit(Source As Notesuidocument, Continue As Variant)

'notzero=source.FieldGetText(“Attachments”)

Dim Doc As NotesDocument

Set Doc = source.Document

notzero=Evaluate(|@Attachments|,Doc)

Dim asvalid As String

'isvalid=Evaluate(|@If(@IsValid;“Valid”;“Not valid”)|)

'isvalid=source.FieldGetText(“ValidField”)

If notzero(0)=0 Then

Messagebox “You must attach the LOV Template”, “LOV Template”

Call source.GotoField(“LOVReqTemplate”)

End If

End Sub

  1. In your case, if the field isn’t last, you could use a field event to save the document and thus call the querysave?

  2. If you don’t need to do anything fancy with the attachment (like copy it to a computed RT field for example), it’s also possible to validate using LS. I have other posts on the subject on the forum, lots of useful answers from people, and it would have worked for my application, except I also needed to do many complex operations with the attachments when the doc was sent…

Subject: RE: How to validade an attachment in a doc before we save it!!!

Thank you fellows. Evaluate @attachments worked for me.;0)

PROBLEM SOLVED

Subject: How to validade an attachment in a doc before we save it!!!

Try this (Notes Client). I used a regular RTF field, but it should work for RTF Lite as well.Sub Querysave(Source As Notesuidocument, Continue As Variant)

'Validate the rtf field here

Dim doc As NotesDocument

Set doc = source.Document



If(Not validateRTF(source, "rtfAttachments")) Then

	

	If (Not source.Document.HasEmbedded) Then

		valid = False			

	Else

		valid = True

	End If

Else

	valid = True

End If



If valid Then

	continue = True

Else

	continue = False

	Msgbox "There was an error validating the attachment field.  Make sure you have attached a file"

End If



If continue Then

	doc.saveoptions = "1"

Else

	doc.saveoptions = "0"

End If

End Sub

Function validateRTF(source As notesuidocument, rtfName As String) As Boolean

On Error Goto ErrSub 



Call source.GoToField(rtfName)

Call source.SelectAll 

Call source.copy

Call source.DeselectAll

Goto OkExit

'This error number will be generated when you

'try to copy the content of the empty field

ErrSub:

If Err = 4407 Then

	'Check to see if the object is embedded in the form.  if not return false

	validateRTF=False

	'Msgbox "Please enter values for the body field",48,"Error"

	Exit Function

End If 

Resume OkExit

OkExit:

validateRTF = True

End Function

…and this on the web. Of course a loop would be optimal here, but overkill for what I needed.

//only validate your upload if there are no attachments already… 3 is the # of upload controls used:

if ( numOfAttachments == 0 || (numOfAttachments ==1 && frm.elements[frm.elements.length-1].checked)) {

if (  frm.upload1.value == '' && frm.upload2.value == '' &&  frm.upload3.value == '' ) {

	link = "<a href=\"JavaScript: document." + frm.name + "." + "upload1" + ".focus();\">Go</a> ";		

	//I use messageArray to store all of my error messages and write them to a div.;

	messageArray[x] =  link + "You must add at least one attachment to the document.";

	frm.upload1.focus();		

	x++

}

}

numOfAttachments is defined in the HTML HEADER

“<script type="text/javascript">”+@NewLine+

" var numOfAttachments = " + @Text(@Attachments) + “;”+@NewLine +

“”