« Return to the blog entry
I modified this and it works awesome! I created a view (that has embedded HTML table attributes like <tr> <td>...) and then embedded that into a form. At the top of that form, just put this:
</form>
<form action="UpdateDocuments?OpenAgent" method="post">
<p><input type="submit" value="Update Documents"></p>
Then embed the view. Then make an agent that runs on "Schedule" but set it to "Never". Then this thing will work!
Thanks so much for the framework to get this started!
Here's the finished agent code:
Sub Initialize
On Error Goto ErroRoutine
'Dim doc As NotesDocument
Dim pairings As Variant
Dim split_pairings As Variant, split_name As Variant
Dim last_processed As String
Dim session As New NotesSession
Dim doc As NotesDocument
Dim editdoc As NotesDocument
Set doc = session.DocumentContext
Set db = session.CurrentDatabase
If doc.HasItem("REQUEST_CONTENT") Then
pairings = Evaluate(|@Explode(REQUEST_CONTENT; "&")|, doc)
'loop all the name/value pairings submitted by the form
Forall v In pairings
'Need to replace + for " " at this point! before it's decoded!
split_pairings = Evaluate(|@URLDecode("Domino"; @ReplaceSubstring(@Explode("|+v+|"; "="); "+"; " "))|)
split_name = Evaluate(|@Explode(@ReplaceSubstring("|+split_pairings(0)+|";"]";"");"[")|)
If Ubound(split_name)>0 Then 'we have something to process (that is, a special bracketed [] field)
'save the last processed document if not same as this one!
If split_name(1) <> last_processed And last_processed<>"" Then
' Call editdoc.Save( True, True)
End If
'get the next document to process
Set editdoc = db.GetDocumentByUNID( split_name(1) )
If Not editdoc Is Nothing Then
If Ubound(split_pairings)>0 Then ' we have a value
Call editdoc.ReplaceItemValue(split_name(0), split_pairings(1))
Else 'blank
Call editdoc.ReplaceItemValue(split_name(0), "")
' last_processed = editdoc.UniversalID
last_processed = split_name(1)
'Now save the last document processed before we left the loop
Call editdoc.Save( True, True)
' Print "Document saved"
End Forall
' Call doc.Save( True, True)
Else
Print "Web doc is not found!"
'$$RETURN to where they came from
'Print "["+web.document.HTTP_Referer(0)+"]"
Print "["+doc.HTTP_Referer(0)+"]"
GracefulExit:
Exit Sub
ErroRoutine:
Print "Error" + Error + " on line " + Cstr(Erl)
Print split_name(0)
Print split_pairings(0)
Print split_name(1)
Print split_pairings(1)
Resume GracefulExit
End Sub
I modified this and it works awesome! I created a view (that has embedded HTML table attributes like <tr> <td>...) and then embedded that into a form. At the top of that form, just put this:
</form>
<form action="UpdateDocuments?OpenAgent" method="post">
<p><input type="submit" value="Update Documents"></p>
Then embed the view. Then make an agent that runs on "Schedule" but set it to "Never". Then this thing will work!
Thanks so much for the framework to get this started!
Here's the finished agent code:
Sub Initialize
On Error Goto ErroRoutine
'Dim doc As NotesDocument
Dim pairings As Variant
Dim split_pairings As Variant, split_name As Variant
Dim last_processed As String
Dim session As New NotesSession
Dim doc As NotesDocument
Dim editdoc As NotesDocument
Set doc = session.DocumentContext
Set db = session.CurrentDatabase
If doc.HasItem("REQUEST_CONTENT") Then
pairings = Evaluate(|@Explode(REQUEST_CONTENT; "&")|, doc)
'loop all the name/value pairings submitted by the form
Forall v In pairings
'Need to replace + for " " at this point! before it's decoded!
split_pairings = Evaluate(|@URLDecode("Domino"; @ReplaceSubstring(@Explode("|+v+|"; "="); "+"; " "))|)
split_name = Evaluate(|@Explode(@ReplaceSubstring("|+split_pairings(0)+|";"]";"");"[")|)
If Ubound(split_name)>0 Then 'we have something to process (that is, a special bracketed [] field)
'save the last processed document if not same as this one!
If split_name(1) <> last_processed And last_processed<>"" Then
' Call editdoc.Save( True, True)
End If
'get the next document to process
Set editdoc = db.GetDocumentByUNID( split_name(1) )
If Not editdoc Is Nothing Then
If Ubound(split_pairings)>0 Then ' we have a value
Call editdoc.ReplaceItemValue(split_name(0), split_pairings(1))
Else 'blank
Call editdoc.ReplaceItemValue(split_name(0), "")
End If
' last_processed = editdoc.UniversalID
last_processed = split_name(1)
End If
End If
'Now save the last document processed before we left the loop
Call editdoc.Save( True, True)
' Print "Document saved"
End Forall
'Now save the last document processed before we left the loop
' Call doc.Save( True, True)
Else
Print "Web doc is not found!"
End If
'$$RETURN to where they came from
'Print "["+web.document.HTTP_Referer(0)+"]"
Print "["+doc.HTTP_Referer(0)+"]"
GracefulExit:
Exit Sub
ErroRoutine:
Print "Error" + Error + " on line " + Cstr(Erl)
Print split_name(0)
Print split_pairings(0)
Print split_name(1)
Print split_pairings(1)
Resume GracefulExit
End Sub