• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 663
  • Last Modified:

Unable to delete profile document in database in R6.5

Hello all,

I am unable to delete a profile document in a database even though I created it. I am also manager of that database. I get a "You are not authorized to perform that operation". Am I missing something? The code I am using is below (many thanks to zvonko). It's a bit urgent hence the number of points. Thank you.

Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim deldoc As NotesDocument
      Dim delcount As Integer
      Set db = session.CurrentDatabase
      Set dc = db.GetProfileDocCollection("Setup")
      Set doc = dc.GetFirstDocument()
      delcount = 0
      While Not(doc Is Nothing)
            If doc.Creator(0) = "Jade Quek/Los Angeles/IBM" Then
                  Print "Deleteing profile: " & doc.Form(0) &_
                  " for: " & doc.Creator(0)
                  Set deldoc = doc
                  Call deldoc.Remove(True) <-- where error message shows up
                  delcount = delcount + 1
            End If
            Set doc = dc.GetNextDocument(doc)
      Wend
      Print delcount & " Profile document(s) deleted"
0
notesrookie
Asked:
notesrookie
  • 8
  • 4
  • 2
  • +1
1 Solution
 
brwwigginsCommented:
Do you have rights to run agents on the server?
0
 
notesrookieAuthor Commented:
Yes I do, through a group, for unrestricted, restricted, and simple and formula agents. I been able to run agents before but this is the first time I'm deleting a profile document.
0
 
notesrookieAuthor Commented:
It's also a private agent if it has any bearing ...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
brwwigginsCommented:
Do you get the error the first time through or only on subsequent runs? I'm not sure about the code anyways because when you remove the deldoc that's the same are removing doc (it's the same document).

I had better luck with this script

Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim deldoc As NotesDocument
Dim delcount As Integer
Set db = session.CurrentDatabase
Set dc = db.GetProfileDocCollection("calcolorprofile")
Set docNext=dc.GetFirstDocument
Set doc=docNext
      
While Not(doc Is Nothing)
      Set docNext = dc.GetNextDocument(doc)
If doc.Creator(0) = "Jade Quek/Los Angeles/IBM" Then

      Print "Deleteing profile: " & doc.Form(0) &_
            " for: " & doc.Creator(0)
            Call doc.Remove(True)
            delcount = delcount + 1
            Set doc = docNext
      Wend
      Print delcount & " Profile document(s) deleted"
0
 
brwwigginsCommented:
sorry bad cut and paste...

Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim deldoc As NotesDocument
Dim delcount As Integer
Set db = session.CurrentDatabase
Set dc = db.GetProfileDocCollection("calcolorprofile")
Set docNext=dc.GetFirstDocument
Set doc=docNext
     
While Not(doc Is Nothing)
     Set docNext = dc.GetNextDocument(doc)
If doc.Creator(0) = "Jade Quek/Los Angeles/IBM" Then
     Print "Deleteing profile: " & doc.Form(0) &_
      " for: " & doc.Creator(0)
     Call doc.Remove(True)
     delcount = delcount + 1
      Set doc = docNext
End If
Wend
Print delcount & " Profile document(s) deleted"
0
 
notesrookieAuthor Commented:
Let me try that and I'll get back to you. Hmmm - I appear to go into a loop where delcount is never incremented.
0
 
notesrookieAuthor Commented:
I moved the "Set doc = docNext" line to outside the If loop but I still get the same error message about not not being authorized.
0
 
notesrookieAuthor Commented:
And I get the error the first time I run through the agent.
0
 
brwwigginsCommented:
sounds like the server is not picking up your credentials through the group. I ran the agent on a database with no problem.

Can you add your name explicitly to the server?
0
 
notesrookieAuthor Commented:
Let me do that and test. If these are not dynamic fields I'll have to wait and restart the server. Thanks.
0
 
Sjef BosmanGroupware ConsultantCommented:
Even a Manager needs Delete permission in the ACL.
0
 
mbonaciCommented:
Hi notesrookie,
just a couple of suggestions (nothing to do with user's rights).

When you're deleting the doc from the collection call this procedure instead of using temporary document (in your case "doc") inside loop:

Sub DeleteCurrentDocAndGetNext( cur As NotesDocument, c As NotesDocumentCollection )
    'Mb¤, 02.03.2003.
    On Error 4434 Resume Next   'Error: "Document was allready deleted from collection"
    Dim prev As NotesDocument
   
    Set prev = cur
    Set cur = c.GetNextDocument( cur )
    Call c.DeleteDocument( prev )    
End Sub

on your example:

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim deldoc As NotesDocument
    Dim delcount As Integer
    Set db = session.CurrentDatabase
    Set dc = db.GetProfileDocCollection("calcolorprofile")
    Set docNext=dc.GetFirstDocument
     
    While Not(docNext Is Nothing)
        If docNext.Creator(0) = "Jade Quek/Los Angeles/IBM" Then
            Print "Deleteing profile: " & docNext.Form(0) & " for: " & docNext.Creator(0)
            Call DeleteCurrentDocAndGetNext( docNext, dc )
            delcount = delcount + 1
        End If
    Wend    'the sub has changed the docNext, so the loop exits if it was the last doc in the collection

    Print delcount & " Profile document(s) deleted"



Another suggestion:
If you want to delete profile doc that's obtained using db.GetProfileDocument (to avoid your "if docNext.Creator...", I presume you want to delete personal profile doc) use something like this:

First get the doc using
    db.GetProfileDocument( "calcolorprofile", "Jade Quek/Los Angeles/IBM" )
and then call this:

Sub DeleteDocUsingNoteID( db As NotesDatabase, doc As NotesDocument )
    'Mb¤, 02.11.2004.
    'This procedure deletes the received doc using it's NoteID
    'Profile doc can't be deleted any way but this after getting it using db.getProfileDocument (automatically saves the doc)
    Dim pdoc As NotesDocument
    Dim noteID As String
   
    noteID = doc.NoteID
    Set doc = Nothing

    Set pdoc = db.GetDocumentByID( noteID )
    If Not pdoc Is Nothing Then
        Call pdoc.RemovePermanently( True )
    End If    
End Sub


Hope this helps,
Marko
0
 
notesrookieAuthor Commented:
Marko - Let me try that and see what happens. Thanks.
0
 
mbonaciCommented:
notesrookie,
keep in mind that this, as I said, wont resolve your problem with user rights.

Implement it after you figure out what's causing your error.

If it's author field this may help:
http://www-10.lotus.com/ldd/46dom.nsf/11a0b6a64ffb3d8d85256a4c004f1bbd/e0359d10a2307d1885256c61000707b7?OpenDocument


Marko
0
 
notesrookieAuthor Commented:
Marko - Your code worked. I was able to see using the debugger that the number of profiles reduced by one in my test database. I wasn't able to use the collection call as I was getting an error message about something about the enumerator (can't remember what now) being full. So your 2nd suggestion was great. Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now