开发者

Validating Attachment in Richtext field

I am using below code to validate the Attachment in Richtext field.

If I will not used Call source.Refresh(True) then validation is not working, but this code is also refreshing document everytime querysave is called in buttons.

So is there any option or any other idea so that I should not user this Refresh part or entire code to validate .

If anybody have more efficient code then please share this.

If Source.Document.YesNo20(0)="Yes" Then
    Call source.Refresh(True)
    Dim rtitem As NotesRichTextItem
    Set rtitem = source.Document.GetFirstItem( 开发者_JAVA百科"Atchmnt20" ) 
    NotesEmbeddedObjectArray = rtitem.EmbeddedObjects
    If Isempty ( NotesEmbeddedObjectArray ) Then 
        Messagebox "Please enter an attachment in 20a. As you selected option Yes"
        continue=False
        Exit Sub
    End If 
End If


There's a way in LotusScript to check attachments presence even for new (not saved) documents.

Create a hidden computed field, for instance AttachmentNames with formula:

@If(@AttachmentNames!=""; "1"; "");

In LotusScript do the following:

'in new documents Form field may be empty
If doc.Form(0) = "" then    
    doc.Form = "YourFormAlias"    
End If

'computing doc contents with the form
call doc.ComputeWithForm(false, false)

If doc.AttachmentNames(0) = "" then    
 MsgBox "Please attach a file",,"Attention"
 Continue = False 'if you are running this code in QuerySave
 Exit Sub
End If


Validating rich text fields in Lotus Notes is a bit of a dark art, but can you not just do this? (where doc is the back-end):

If(doc.HasEmbedded) Then Continue = True

There are other things you can do. Check this Lotus Developer Domain post, which covers attachments, text, embedded objects, all sorts:

http://www-10.lotus.com/ldd/nd6forum.nsf/0/8b3df10667d355768525719a00549058


Can you validate RT field with formula?

I created a hidden field below my rich text field with this Input Validation formula:

REM {Validate just when saving};
@If(!@IsDocBeingSaved; @Return(@Success); "");

REM {Should contain some file};
_filenames := @AttachmentNames;
@If(
    @Elements(_filenames)=0;
    @Return(@Failure("You should attach at least one file"));
    @Success);


Assuming that you want to avoid the Refresh because it takes too long, here is what you may want to look at and if feasible, try to change:

  1. Maybe you can use the "Entering" event of the RichText field in conjunction with a global variable (in the form) to skip the Refresh in your code, if the RichText field wasn't touched at all.
  2. Are there keyword fields with "Refresh choices on document refresh" option enabled that may be safe to disable? Or even place a button that would bring up a dialog and populate the field with the selected keyword(s) - refreshing the choices won't be neccessary then, as you can always present up-to-date choices through @DbColumn/@DbLookup or NotesUIWorkspace.PickListStrings.
  3. Is there any code (LotusScript or Formula) in "Queryrecalc" and/or "Postrecalc" form events that may be possible to optimize? For example by using a global variable (in the form) as a flag whether to execute the code in Queryrecalc/Postrecalc - set it to false just before calling Refresh in your code, then set it back to true (because this Refresh only serves to update the RichText field to the backend document).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜