In the WebQuerySave I add an extra macro to run
@Command([ToolsRunMacro]; "(ResponseRedirect)");
Then in that agent I have this code:
Sub Initialize
%REM
Work out where to direct the user and print the url
If the topic has more than 30 replies we need to send them to the correct page rather than just the first one
To do that we need to calculate how many responses there are and use ?OpenView&Start=1.29 or 1.59 etc
%END REM
<br/>
Dim s As New NotesSession<br/>
Dim col As NotesDocumentCollection<br/>
Dim response As NotesDocument<br/>
Dim catDoc As NotesDocument<br/>
Dim view As NotesView<br/>
Dim start As Integer<br/>
Dim responseNum As Integer<br/>
Dim startText As String<br/>
<br/>
Dim createDate As Variant 'test var<br/>
<br/>
start = 1<br/>
responseNum = 0<br/>
startText = ""<br/>
<br/>
Set db=s.CurrentDatabase<br/>
Set ctx = s.DocumentContext<br/>
Set profile = db.GetProfileDocument("Configuration_Profile")<br/>
Set view = db.GetView("(LookupCategories)")<br/>
Set catDoc = view.GetDocumentByKey(ctx.Category1(0))<br/>
<br/>
Set doc=db.GetDocumentByUNID(ctx.GetItemValue("MainUNID")(0)) 'Main Topic - parent document<br/>
If Not doc Is Nothing Then<br/>
Set col = doc.Responses<br/>
Call col.AddDocument(doc)<br/>
<br/>
If ctx.IsNewNote Then<br/>
' now set the start number<br/>
If col.Count => 30 Then<br/>
start = Fix((col.Count + 1)/ 30)<br/>
start = start * 30 - 1<br/>
startText = "&Start=1." & start<br/>
End If<br/>
Else<br/>
<br/>
'it was edited so go back to this post within the view<br/>
'need to find which number post this is in the collection (only if it's more than one page ie 30 docs)<br/>
If col.Count > 30 Then<br/>
Set response = col.GetFirstDocument<br/>
While Not response Is Nothing<br/>
responseNum = responseNum + 1<br/>
createDate = response.Created<br/>
If response.UniversalID = ctx.UniversalID Then<br/>
'now we've found the current doc in the collection<br/>
If responseNum > 30 Then<br/>
start = responseNum/ 30<br/>
start = start * 30 -1<br/>
startText = "&Start=1." & start<br/>
End If<br/>
Set response = Nothing<br/>
Else<br/>
Set response = col.GetNextDocument(response)<br/>
End If<br/>
Wend<br/>
End If<br/>
<br/>
End If<br/>
Else<br/>
Print "[" & profile.NewsletterServerURL(0) & "/" & Replace(db.FilePath,"\","/") & "/WebBoardMainActiveCategorized?OpenView&RestrictToCategory=" & ctx.Category1(0) & "]"<br/>
Exit Sub<br/>
End If<br/>
<br/>
If Not catDoc Is Nothing And catDoc.UseApprovalWorkflow(0) = "Y" And ctx.Published(0) = "N" Then<br/>
Print {<html><head><meta http-equiv="refresh" content="3;URL=}& profile.NewsletterServerURL(0) & "/" & Replace(db.FilePath,"\","/") & "/WebBoardSub?OpenView" & startText & "&RestrictToCategory=" & doc.UniversalID & "#bottom" &{"></head><body><h3>Thank you for posting to the forum.</h3>Please note that there may be a delay before your post appears on the site as it is being moderated.</body>}<br/>
Else<br/>
Print "[" & profile.NewsletterServerURL(0) & "/" & Replace(db.FilePath,"\","/") & "/WebBoardSub?OpenView" & startText & "&RestrictToCategory=" & doc.UniversalID & "#" & ctx.UniversalID "]"<br/>
End If<br/>
<br/>
End Sub