求教用script提取表单数据的方法
两个form1,form2
form1包含的域:name,id,telephone
form2包含的域:name,id,change
V_form1是一个视图,包含form1的name,id列;
在V_form1视图上有一个操作“变更”,click之后弹出form2,
我希望form2的name,id,可以利用lotus script编程根据form1的name来取到;
以前我用sql 语句实现的方法是:select form1.name,form1.id from form1 where form1.name="大明贸易公司"
实现方法:
1.取到当前文档的“客户名称”;source. fieldgettext("custom_name")---实现;
2.取到“客户基本情况”中的所有“客户”名称;---在视图V_form1
3.根据步骤2匹配步骤1的结果得到“客户代码” ;---未实现
4.对域custom_id进行赋值“客户代码”---实现
我使用了notesView,NotesDocumentCollection,NotesDocument希望能根据form1的name来取到id,并将name,id的值写进form2.name,form2.id域;
我用script实现如下:
Sub Postopen(Source As Notesuidocument)
Dim WorkSpace As notesuiworkspace
Dim UIDoc As notesuidocument
Dim session As New NotesSession
Dim db_custom As NotesDatabase
Dim View_custom_name As notesView
Dim custom_id As String
Dim myDoc As NotesDocument
Dim mydc As NotesDocumentCollection
Set UIDoc=source
Set db_custom_name=session.currentdatabase
Set View_custom_name=db_custom_name.getview("V_form1")
Set mydc = view.GetAllDocumentsByKey(UIDoc.fieldgettext("custom_name"), True)
REM Set column=view_custom_name.column(5)
custom_id=UIDoc.fieldgettext("custom_name")
Call UIDoc.FieldSetText("custom_id",custom_id)
REM set field
REM Set WorkSpace = New notesuiworkspace
REM Set UIDoc = workspace.currentdocument
REM Msgbox "验证测试!"
If UIDoc.fieldgettext("custom_name") = "" Then
Msgbox "企业名称 不能是是空值",32+0,"系统提示"
Else
REM 保存此表单
UIDoc.Save
Exit Sub
End If
End Sub
总结:我希望能根据一个"客户名称"用script语句取到一个表单上的其他值:id,telephone....;
不胜感激;
bismark2000
问题点数:100、回复次数:14Top
1 楼fokker(独孤龙)回复于 2002-04-15 16:09:28 得分 80
我觉得你可以把查找、赋值的代码写进操作“变更”中比较好一点。Top
2 楼itrain(雨儿)回复于 2002-04-15 16:30:56 得分 20
看你的需求似乎不难呀,不过为什么一定要用lotuscript呢?公式语言不可以么??Top
3 楼bismark2000()回复于 2002-04-15 17:04:26 得分 0
回 fokker(独孤龙) ,写进操作“变更”和在窗体POSTOPEN事件应该是没有多大区别的;
回itrain(雨儿) :你能否用一个例子,用公式语言实现该功能?
我的新想法:采用NotesDocument类来实现该功能
步骤1:取到当前文档的“客户名称”;source. fieldgettext("custom_name")
步骤2:用NotesDocument类匹配source. fieldgettext("custom_name"),得到对应该("custom_name")的在form1上的id,telephone;
步骤3:id,telephone赋值给form2
二位对此的看法?Top
4 楼itrain(雨儿)回复于 2002-04-15 17:13:15 得分 0
你是不是要实现这样的功能:
在视图中,点中一个文档1,然后点操作“变更”,新建一个文档2,要使文档2中的有的域值是文档1中的域值?Top
5 楼fokker(独孤龙)回复于 2002-04-15 17:35:18 得分 0
这是我写的操作“变更”
Sub Click(Source As Button)
Dim s As New notessession
Dim ws As New notesuiworkspace
Set uiview = ws.currentview
Dim doc As notesdocument
Dim dc As Notesdocumentcollection
Set dc=uiview.documents
If dc.Count<=0 Then
Messagebox "Please select document"
Exit Sub
End If
Dim i As Integer
Set doc=dc.Getfirstdocument()
Dim newuidoc As notesuidocument
Do
Set newuidoc=ws.Composedocument("","","form2")
Call newuidoc.FieldSetText("name",doc.name(0))
Call newuidoc.FieldSetText("id",doc.id(0))
Set doc=dc.Getnextdocument(doc)
Loop While Not(doc Is Nothing)
End SubTop
6 楼fokker(独孤龙)回复于 2002-04-15 17:40:32 得分 0
操作“变更”是在视图V_form1里面,V_form1是取的全部form1的文档,在V_form1中选中文档并点击操作“变更”后会自动使用表单form2胜成新文档并将对应的form1的文档中的数据写入新文档中。Top
7 楼bismark2000()回复于 2002-04-15 18:07:54 得分 0
回itrain(雨儿) ( ) :
你是不是要实现这样的功能:
在视图中,点中一个文档1,然后点操作“变更”,新建一个文档2,要使文档2中的有的域值是文档1中的域值?
-----是这样的意思!
bismark2000Top
8 楼fokker(独孤龙)回复于 2002-04-15 18:43:45 得分 0
我的操作已经实现这个功能了Top
9 楼itrain(雨儿)回复于 2002-04-16 18:14:33 得分 0
将文档2的表单的属性中,公式继承选定文档中的数值一项选中。
再将文档2的表单上的域设为计算域,公式上写文档1中的域名。
OK!Top
10 楼bismark2000()回复于 2002-04-17 02:00:45 得分 0
to fokker(独孤龙) :
我按照你的程序去运行,经跟踪发现uiview可以取到视图名称,但是dc却没有取道相应的文档,我跟踪发现dc.count=0----但是在该视图中有20个文档!!
不知道是否如此?还望指教。Top
11 楼tx18(www.sqlserver.com.cn)回复于 2002-04-17 08:45:01 得分 0
小问题,不用弄那么复杂。
你只要把V_form1中文档按你要变更的条件分类,form2中的change域设为对话框列表,用公式@DbColumn("";"";"V_form1";1)返回条件列表,并选中按关键字变化刷新域,name可以用公式@If(change="";"";@DbLookup("";"";"V_form1";change;name))返回值,id亦然Top
12 楼fokker(独孤龙)回复于 2002-04-17 09:15:30 得分 0
to bismark2000():
按照我的代码,你得在视图中选中文档才行(就是在它的前面打勾),你选中的几个文档dc.count就等于几。因为:Set dc=uiview.documents反映的是选中的文档。
Top
13 楼fokker(独孤龙)回复于 2002-04-17 09:21:34 得分 0
如果你想取得视图中的所有文档,那就更改一下代码:
Sub Click(Source As Button)
Dim s As New notessession
Dim ws As New notesuiworkspace
Set uiview = ws.currentview
Set view = uiview.View
Dim doc As notesdocument
Set doc=view.Getfirstdocument()
If doc Is Nothing Then
Messagebox "No docuemnts!"
Exit Sub
End If
Dim newuidoc As notesuidocument
Do
Set newuidoc=ws.Composedocument("","","form2")
Call newuidoc.FieldSetText("name",doc.name(0))
Call newuidoc.FieldSetText("id",doc.id(0))
Set doc=view.Getnextdocument(doc)
Loop While Not(doc Is Nothing)
End SubTop
14 楼bismark2000()回复于 2002-04-17 14:44:20 得分 0
ok,问题解决。给分Top




