Search code examples
lotus-dominolotusscript

Trying to use adminp.DeleteReplicas followed by adminp.ApproveReplicaDeletion gives error "Invalid Approval Request note"


I am trying delete a database and any associated replicas using LotusScript adminp calls. This is basically the code:

Dim session As New NotesSession
Dim adminp As NotesAdministrationProcess
Set adminp = session.CreateAdministrationProcess("Software_Server") 
noteid$ = adminp.DeleteReplicas("Software_Server", "Guys1") 
If noteid$ <> "" Then 
    Call adminp.ApproveReplicaDeletion(noteid$) 'This is where the error is thrown
End If

The first adminp call is successful and returns a noteid, and if I look in the admin requests database can see the document. The next call to ApproveReplicateDeletion results in the error "Invalid Approval Request note"

The documentation doesn't contain any examples for the adminp approve methods. I have a feeling that maybe the second request cannot be called until much later when adminp has processed the first request?

Also related question, do I only have to make this request on a single server and it will remove replicas on all other servers, or do I need to make this request for each server?


Solution

  • So this is a bit more complicated than the help gives any indication of, and might explain why I couldn't find any examples on the internet on how to do it. So the Workflow for using AdminP is as Follows:

    1. Create the request to get the noteID for the initial noteid of the DeleteReplicas request. The returned noteID is not the one that is used to approve the delete replica request. noteid$ = adminp.DeleteReplicas("Software_Server", "Guys1")
    2. This creates a document in the admin.nsf db for the initial request, but the approval docs don't yet exist, for the server to create those, the adminp process must run.
    3. So in the code send a Console command to the Server "tell adminp process now"
    4. Sleep the agent for a few seconds to give adminp time to process the request (this will also fire off any other waiting adminp requests unfortunately)
    5. Now new documents will have been created in the admin database, that are awaiting approval by an admin. These documents contain the noteids that should be sent the approvereplicadeletion
    6. To get them, first lookup the notes document by the noteID in the admin db obtained in step 1
    7. Using that noteid for the document, get the field value ProxyOriginatingRequestUNID from the document.
    8. using this UNID value, perform a getalldocumentsbykey on the view ($AllRequestsbyOriginatingUNID)
    9. if the returned document has a ProxyAction field with a value of "82", this is an approval request document. This documents noteid can be passed to approveReplicaDeletion to have adminp remove the database next time it processes requests.
    10. You can either send a console command to process adminp again, or just wait for the database deletions etc. to happen next time around.