在Javascript中直接获取Lotus Notes中的视图信息/记录

Directly Getting View Information/Records in Lotus Notes in Javascript

本文关键字:视图 信息 记录 Notes Lotus Javascript 获取      更新时间:2023-09-26

基本上我需要从lotus notes本身的视图访问一些记录或数据。我不能使用@DBLookup,因为我们的目标是不刷新表单。我知道使用AJAX是可能的,虽然我还没有尝试过AJAX,如果你有一个详细的教程,请在这里分享。

我的主要问题是基本上有没有其他更容易的方法来访问视图中的这些记录?在字段的javascript部分直接编码。非常感谢。

基本上@DbLookup = "?"Javascript(非AJAX).

我将按照Torsten的建议,创建一个Lotusscript代理,它执行查找并返回带有数据的JSON对象。然后,您可以使用Javascript或(更简单)jQuery从您的网页对该代理进行ajax调用。

我在我的博客上贴了一些代码。它正在做类似的事情,但不是执行视图查找,而是根据文档ID检索特定文档的值。你可以在这里找到代码和更详细的解释:http://blog.texasswede.com/code-snippet-jquery/

这是jQuery代码:
function loadNotesFields(docunid) {
    var notesfieldname = "";
    $.ajax({
        url: "/database.nsf/ajax_GetNotesFieldFields?OpenAgent", 
        data: {"NotesUNID":docunid},
        cache: false
    }).done(function(data) {
        $('input[notesfield]').each(function() {
            notesfieldname = $(this).attr("notesfield");
            $(this).val(data[notesfieldname]);
        });
    });
}
下面是Lotusscript代码:
Dim urldata List as String
Sub Initialize
    Dim session As New NotesSession
    Dim webform As NotesDocument
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim urlstring As String
    Dim urlarr As Variant
    Dim urlvaluename As Variant
    Dim i As Integer
    Dim json As String
    Set webform = session.DocumentContext
    '*** Remove leading "OpenAgent" from Query_String
    urlstring = StrRight(webform.Query_String_Decoded(0),"&")
    '*** Create list of arguments passed to agent
    urlarr = Split(urlstring,"&")
    For i = LBound(urlarr) To UBound(urlarr)
        urlvaluename = Split(urlarr(i),"=")
        urldata(urlvaluename(0)) = urlvaluename(1)
    Next
    Set thisdb = session.CurrentDatabase
    '*** Create content header for return data
    Print "content-type: application/json"
    '*** Get Notes document baed on NotesUIND argument
    Set doc = db.GetDocumentByUNID(urldata("NotesUNID"))
    '*** Build JSON for all fields in document except $fields
    json = "{" + Chr$(13)
    ForAll item In doc.Items
        If Left$(item.Name,1)<>"$" Then
            json = json + |"| + item.Name + |":"| + item.Text + |",|+ Chr$(13)
        End If
    End ForAll
    '*** Remove trailing comma and line break
    json = Left$(json,Len(json)-2)  
    json = json + "}"
    '*** Return JSON
    Print json  
End Sub

如果这是一个XPages问题,那么答案很简单:使用JavaScript @DBLookup。

对于"经典"web开发来说,这并不容易。您需要编写一个代理,它以您想要的任何格式返回@DBLookup的结果,并使用ajax调用调用该代理。它看起来像这样:

LotusScript- Agent,触发none

Dim ses as New NotesSession
Dim db as NotesDatabase
Dim viw as NotesView
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
Set db = ses.CurrentDatabase
Set viw = db.GetView( "YourLookupView" )
Set dc = viw.GetAllDocumentsByKey( "YourLookupKey" )
Set doc = dc.GetFirstDocument
While not doc is Nothing
  Print doc.GetItemValue( "NameOfItemToReturn" )(0)
  Set doc = dc.GetNextDocument( doc )
Wend

这个代理将返回一个包含所有值的"page",每个值一行。然后,在ajax- return-函数中,您可以对这些值做您想做的事情。

通常你不是简单地打印值,而是返回json- object,或者一些xml-结构,或者已经html作为有序列表,或者其他什么,但是原则应该是明确的。

然后你调用代理(例如ajax调用):hxxp://server/db.nsf/AgentName?OpenAgent

另一种可能性是使用hxxp://server/db.nsf/YourLookupView?ReadViewEntries&restricttocategory=YourCategoryhxxp://server/db.nsf/YourLookupView?ReadViewEntries&restricttocategory=YourCategory&OutputFormat=json这样的url,并使用"原生"javascript解析结果…