Response delete

I create a document that is a response, it works fine, and when i delete the parent document the response doesnt get deleted!

Why and how?

Here is the code!

Thanks

Set email = New NotesDocument(dbnew)

email.Form = "E_POS"

email.tvrtka = doc.organizacija

email.adresa = doc.adresa

email.post=doc.post_broj





Call email.Save(True,False)



	

Call email.MakeResponse(newdoc)

Call email.Save(True,True)

Call ws.EditDocument(True,email)

Call ws.CurrentDocument.Save

Subject: Response delete

Deleting a parent document will not delete all the response documents automatically. They will become orphan documents.

If you want this functionality you will have to code it yourself using the Querydocumentdelete event in the Database Script section or you could write an agent that runs overnight and deletes all the orphan documents in the database.

Subject: RE: Response delete

Sorry i wasnt clear enough!

I am modifying a database, it already works in the manner that if i delete a parent doc his responses also get deleted! There is an action that creates the parent and 3 responses and i have added the 4th response with the code i have posted! And now when i delete the parent the 3 resp get deleted but the 4th the one i have created stays in the database

Subject: RE: Response delete

Are you deleting the parent document from the view level and if so does the 4th response document display correctly in the view before the deletion?

Can you post your code that deals with deleting the documents.

Subject: RE: Response delete

Yes i delete from view with “Delete” key on the keyboard!

Here is the code that is in QueryDocumentDelete(I didnt wrote it):

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)

'continue = True

'Exit Sub



Dim s As New NotesSession     

Dim ws As New NotesUIWorkspace     

Dim dc As NotesDocumentCollection

Dim Responses As NotesDocumentCollection

Dim doc As NotesDocument





 ' zabrana brisanja sa tipkovnice

If  ws.CurrentView.View.Name = "Deleted Documents" Then

	continue = False

	Exit Sub

End If

'The first step is to get a handle on all the documents marked by the user for deletion. This is done by

'using the Document property of the NotesUIdatabase which returns a document collection of all the documents marked for deletion.

Set dc = Source.Documents

'The next step is to have the user verify that Yes they want the documents deleted. The messagebox statement is nested in the If statement.

'If the user answers No to the question, no processing is performed on the selected documents.

Beep

If Messagebox("Odabrali ste " & dc.Count & " dokumenata da obrišete.  Da li ste sigurni?" , _

36 , "Potvrda brisanja dokumenata") = 6 Then

'If the users answered yes, we get a handle on the first document in the collection. The Do statement forces the code to continue

'until the variable doc is Nothing, meaning a Set doc = … returned nothing.

	Set doc = dc.GetFirstDocument          

	

	Do Until (Doc Is Nothing)

'This is the heart of the operation. The view selection formulas in the sample database are based on the form used to create the document, the

'field value is changed to “Deleted Documents” If your view selection formulas are based on other field, you would have to change that field’s value

'here to ensure the deleted document does not appear in that view.

		doc.OldForm = doc.Form               

		doc.Form = "Deleted Document"

'This code is used to identify who and when the document was deleted.

		doc.DeletedBy = S.CommonUserName

		doc.DeletedOn = Now

'The cha nges made to the document are saved.

		Call Doc.Save(True, False)

'Check to see the document has at least one response document.

'If there is at least one response document, the subroutine ProcessResponseDocuments is called.

'This is done to avoid orphaned response documents.

’ Although the user may have selected the response documents at the same time,

’ I have found that it is better to process them as if the user did not select them.

'If you count on the user selecting the main document and all of its descendants,

’ you are bound to have orphaned documents.

		Set Responses = doc.Responses

		If Responses.Count >0 Then

			continue = False

			Call ProcessResponseDocuments(s, Responses)

		Else

			continue= True

		End If

'Get a handle on the next document in the document collection and start the process again.

		Set doc = dc.GetNextDocument(doc)               

	Loop

'Refreshs the view the user has open. This removes all the documents which have just been processed.

	Call ws.ViewRefresh

	

End If

'This Continue = False disables the conventional document deletion.

Continue = False

End Sub

Subject: RE: Response delete

The code that deletes the responses is here

Set Responses = doc.Responses

If Responses.Count >0 Then

continue = False

Call ProcessResponseDocuments(s, Responses)

Else

continue= True

End If

Are you sure that the 4th response document you create is a response to a main document and not a response to a response document?

doc.Responses does not return response to response documents in the document collection which would explain why it is not being deleted.

If not can you post the code for the ProcessResponseDocuments(s, Responses) function as this is where the deletion is taking place.

Subject: RE: Response delete

Ill post the whole code! The form E_POS or email wont delete the othesr will!

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim s As New NotesSession



Dim db As NotesDatabase

Dim dbnew As New NotesDatabase( "", "" )

Dim view As NotesView

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument			' tekući dokument - tj. mail koji treba otvoriti





Dim dc  As  NotesDocumentCollection



Dim newdoc As NotesDocument

Dim prijava As NotesDocument

Dim nalog As NotesDocument





Dim key As String

Dim br_predmet As String

Dim doc_edit As String

Dim doc_read As String

Dim docID As String



Set db = s.CurrentDatabase

Set uidoc = ws.CurrentDocument

Set doc = uidoc.document



' označavanje tekuće prijave kao rješene

uidoc.EditMode = True

Call uidoc.FieldSetText("doc_status","Rješeno")

Call uidoc.Save

’ slanje obavijesti osobi koja prima radni nalog

'Set mailDoc = New NotesDocument(db)

'Set rtitem = New NotesRichTextItem(newDoc,"Body")

'

'Call rtitem.AppendText ("Radni nalog - " & newDoc.doc_broj(0)  & " - spreman na rješenje:")

'Call rtitem.AddNewLine(2)

'Call rtitem.AppendText("  Broj naloga:  " & newdoc.doc_broj(0))

'Call rtitem.AddNewLine(1)

'Call rtitem.AppendText("  Korisnik:  " & newdoc.organizacija(0))

'Call rtitem.AddNewLine(1)			

'Call rtitem.AppendText ("  http://" & newdoc.Server_Name(0) & "/" & newdoc.DBPath(0) &"/0/" & newdoc.UniversalID & "?OpenDocument")

'

'maildoc.Form = "Bookmark"

'mailDoc.Subject = newdoc.FormName(0)  & " - radni nalog za kabelski internet br. " & newdoc.doc_broj(0) & " od " & newdoc.organizacija(0)

'mailDoc.SendTo = "zeljko.crnjac@pincom.net"

'mailDoc.CopyTo = doc.CreatedBy(0)

'Call mailDoc.Send(False)



' promjena statusa na postojećem dokumentu da označava da je obrađena prijava



'Call doc.Save(False,False)



' OTVARANJE  podataka za komitenta

' otvaranje baze da se omogući kopiranje

flag = dbnew.Open( "HERMES/pincom", "pdm.nsf" )

If Not flag Then

	Exit Sub

End If



' prethodna provjera da li postoji prijavljen komitent pod tim imenom

key = doc.jmbg(0)

Set view = dbnew.Getview("(komjmbg)")



Print "Provjera da li je komitent već prijavljen pod zadanim imenom"

'searchformula$ = "(Form = 'komitenti') & kom_naziv  = '" & key & "'" 



'Set dc = dbnew.Search(searchformula$ , Nothing,0)

Set dc = view.GetAllDocumentsByKey(key,True)



If dc.Count > 0 Then

					' ako ne postoji org jedinica ne može se ući u dokument i izlazi se iz upravo kreiranog dokumenta		

	Print "Prijavljen je komitent sa tim podacima"

Else

	' prijava novog komitenta

	Print "Prijava novog komitenta"

	Set newdoc =  New NotesDocument(dbnew)

	newdoc.Form = "komitenti"

	' podaci sa forme	

	newdoc.kom_naziv = doc.organizacija

	newdoc.maticni_broj = doc.jmbg

	newdoc.sif_mjesto =doc.sif_mjesto

	newdoc.sif_drzava = "BiH" 	' Bosna i Hercegovina"

	newdoc.adresa = doc.adresa

	newdoc.post_broj = doc.post_broj

	newdoc.telefon = doc.telefon

	newdoc.mobitel = doc.mobitel

	newdoc.fax =  doc.fax

	newdoc.e_mail =  doc.e_mail

	newdoc.kom_kategorija = "WIC korisnik"	

	newdoc.sif_komregija = "08"		' hercegovačko neretvanska županija

	newdoc.sif_komdjelatnost = "99999"

	newdoc.UserPrijava = doc.UserPrijava

	If doc.FormName(0) = "FizičkaOsobaWIC" Then

		newdoc.sif_komtip = "436" ' "Fizičke osobe - domaće"

	Else

		newdoc.sif_komtip = "440" ' "Pravne osobe (nepovezane) - domaće"

	End If

	

	newdoc.ComputeWithForm False,False

	Call newdoc.Save(False,False)

	

End If



' kreiranje novog predmeta za dosje korisnika 

Print "Kreiranje predmeta"

user = s.CommonUserName



Set newdoc =  New NotesDocument(dbnew)

newdoc.Form = "predmet"



'If newdoc.HasItem("komitent") Then

newdoc.komitent = doc.jmbg

'End If

newdoc.proces = "WIC"

newdoc.naziv_predmet =  doc.organizacija(0)

newdoc.doc_nositelj = Cstr("miljenko buhac")

newdoc.organizacija = doc.organizacija

newdoc.doc_izradio = Cstr(user)

newdoc.predmet_vrsta="WIC"

newdoc.doc_DefRead = Cstr(user)

newdoc.doc_DefEdit = Cstr(user)



Call newdoc.ComputeWithForm(True,False)

Call newdoc.Save(True,False)

'Call ws.CurrentDocument.Refresh

unid_predmeta = newdoc.doc_ID(0)

br_predmet = newdoc.doc_br_predmet(0)

doc_edit = newdoc.doc_edit(0)

doc_read = newdoc.doc_read(0)

' otvaranje tek kreiranog predmeta	

Call ws.EditDocument(True,newdoc)

Call ws.CurrentDocument.Save



'Call ws.CurrentDocument.Close



' kreiranje prijavnice

Print "Kreiranje prijavnice"

Set prijava =  New NotesDocument(dbnew)

prijava.Form = "Prijava"

'If prijava.HasItem("komitent") Then

prijava.komitent = doc.jmbg

'End If



prijava.doc_predmet = doc.organizacija(0)

prijava.komitent = doc.jmbg

prijava.organizacija = doc.organizacija

prijava.doc_broj = Cstr("500-" +doc.doc_broj(0))

prijava.datum_prijava = doc.datum_prijava

prijava.docproces_ID= newdoc.doc_ID

prijava.doc_proces = newdoc.doc_proces

prijava.proces = newdoc.proces

prijava.proces_tip = newdoc.proces_tip

prijava.doc_br_predmet = Cstr(br_predmet)

prijava.OS=doc.OS

prijava.Mkart=doc.Mkart

prijava.vrstdok = "1"

prijava.doc_tip = "Prijavnica" 

newdoc.UserPrijava = doc.UserPrijava



If doc.HasItem("modem") Then

	prijava.modem = doc.modem

End If



prijava.paket = doc.paket

prijava.placanje = doc.placanje

prijava.komentar = doc.komentar

prijava.doc_izradio = Cstr(user)

prijava.doc_DefRead = Cstr(user)

prijava.doc_DefEdit = Cstr(user)

prijava.doc_edit = doc_edit

prijava.doc_read = doc_read



Call prijava.ComputeWithForm(True,False)

Call prijava.Save(True,False)



unid_prijave = prijava.doc_ID(0)

' prijava response na predmet	

Call prijava.MakeResponse(newdoc)

Call prijava.Save(True,True)



' otvaranje kreiranog dokumenta

Call ws.EditDocument(True,prijava)

Call ws.CurrentDocument.Save







'kreiranje email rješenja

Print "Kreiranje e-mail rješenja"

Set email =  New NotesDocument(dbnew)

email.Form = "E_POS"

email.tvrtka = doc.organizacija

email.adresa = doc.adresa

email.post=doc.post_broj

email.mjesto=doc.mjesto

email.doc_izradio = Cstr(user)

email.doc_DefRead = Cstr(user)

email.doc_DefEdit = Cstr(user)

email.doc_edit = doc_edit

email.doc_read = doc_read

email.doc_predmet = doc.organizacija(0)

email.doc_broj = Cstr("500-" +doc.doc_broj(0))

email.docproces_ID= newdoc.doc_ID

email.doc_proces = newdoc.doc_proces

email.proces = newdoc.proces

email.proces_tip = newdoc.proces_tip

email.doc_br_predmet = Cstr(br_predmet)

email.doc_tip = "E-mail rješenje PWIC" 

email.doc_datum=doc.datum_prijava

email.doc_type="Mail"

email.doc_subject=doc.organizacija

email.ComputeWithForm False,False

Call email.Save(True,False)





' prijava response na predmet	

Call email.MakeResponse(newdoc)

Call email.Save(True,True)



' otvaranje kreiranog dokumenta

Call ws.EditDocument(True,email)

Call ws.CurrentDocument.Save

’ generiranje kartice wic

%REM

Set newdoc=  New NotesDocument(db)

newdoc.Form = "WIC"

 'podaci sa forme	prebačeni sa prijavnice

newdoc.jmbg = doc.jmbg

newdoc.UNID_predmeta = unid_predmeta

newdoc.UNID_prijave = unid_prijave

newdoc.organizacija = doc.organizacija

newdoc.doc_broj = doc.doc_broj

newdoc.mjesto=doc.mjesto

newdoc.antena=doc.antena

newdoc.paket=doc.paket

newdoc.placanje=doc.placanje

newdoc.telefon = doc.telefon

newdoc.datum_prijava =  prijava.datum_prijava

newdoc.nalog_datum = Cdat(Now())

newdoc.mobitel=  doc.mobitel 'GetNextFormNumber (db, "Rn-")	

newdoc.doc_status = "Otvoreno"

newdoc.ComputeWithForm False,False

Call newdoc.Save(True,False)



Call ws.CurrentDocument.Close

%END REM

' otvaranje radnog naloga za internu upotrebu-docmanager

	' generiranje radnog naloga

Print "Kreiranje Radnog Naloga"

Set nalog =  New NotesDocument(dbnew)

nalog.Form = "RadniNalogWIC"

' podaci sa forme	prebačeni sa prijavnice

nalog.doc_tip="Radni Nalog"

nalog.doc_broj = Cstr("500-" +doc.doc_broj(0))

nalog.organizacija = doc.organizacija(0)

nalog.adresa = doc.adresa

nalog.mjesto=doc.mjesto

nalog.docproces_ID= doc.doc_ID

nalog.proces = "WIC"

nalog.jmbg=doc.jmbg

nalog.telefon=doc.telefon

nalog.mobitel=doc.mobitel

nalog.OS=doc.OS

nalog.mrezna=doc.Mkart

nalog.paket=doc.paket

nalog.placanje=doc.placanje	

nalog.doc_br_predmet = Cstr(br_predmet)

nalog.doc_izradio = Cstr(user)

nalog.doc_DefRead = Cstr(user)

nalog.doc_DefEdit = Cstr(user)

nalog.doc_edit = doc_edit

nalog.doc_read = doc_read

nalog.modem_1=doc.modem



nalog.nalog_datum = Cdat(Now())

nalog.ComputeWithForm False,False

Call nalog.Save(True,False)



' prijava response na predmet	

Call nalog.MakeResponse(newdoc)

Call nalog.Save(True,True)



' otvaranje tek kreiranog predmeta	

Call ws.EditDocument(True,nalog)

Call ws.CurrentDocument.Save





'kreiranje ugovora-docmanager

Print "Kreiranje ugovora"

Set ugovor =  New NotesDocument(dbnew)

ugovor.Form = "UgovorWICPOS"

' podaci sa forme	prebačeni sa prijavnice

'If ugovor.HasItem("komitent") Then

ugovor.komitent = doc.jmbg

'End If

ugovor.organizacija = doc.organizacija

ugovor.doc_broj = Cstr(doc.doc_broj(0))

ugovor.doc_predmet = doc.organizacija(0)

ugovor.mjesto=doc.mjesto

ugovor.adresa=doc.adresa

ugovor.datum_prijava=doc.datum_prijava

ugovor.docproces_ID= newdoc.doc_ID

ugovor.doc_proces = newdoc.doc_proces

ugovor.proces = newdoc.proces

ugovor.proces_tip = newdoc.proces_tip

ugovor.doc_tip = Cstr("Ugovor")

ugovor.doc_br_predmet = Cstr(br_predmet)

ugovor.doc_izradio = Cstr(user)

ugovor.doc_DefRead = Cstr(user)

ugovor.doc_DefEdit = Cstr(user)

ugovor.doc_edit = doc_edit

ugovor.doc_read = doc_read



'ugovor.nalog_datum = Cdat(Now())



ugovor.paket = doc.paket

ugovor.placanje = doc.placanje

ugovor.modem=doc.modem



ugovor.ComputeWithForm False,False

Call ugovor.Save(True,False)



' prijava response na predmet	

Call ugovor.MakeResponse(newdoc)

Call ugovor.Save(True,True)



' otvaranje tek kreiranog predmeta	

Call ws.EditDocument(True,ugovor)

Call ws.CurrentDocument.Save

doc.doc_status = "Rješeno"

End Sub

Subject: RE: Response delete

In the form properties is E_POS set to be a response document? If not then the following code will initially save it as a response document to newdoc but when it is opened in edit mode and saved again it will revert to being a main document.

Call email.MakeResponse(newdoc)

Call email.Save(True,True) ’ otvaranje kreiranog dokumenta

Call ws.EditDocument(True,email)

Call ws.CurrentDocument.Save ’ generiranje kartice wic %REM

Otherwise I have no idea and suggest that you run the code through in the debugger keeping an eye on newdoc Responses property to see what is happening and when it gets incremented.

Subject: RE: Response delete

YEEEEEEEEEEEEEEEEEEEEESSSSSS!

Thanks a lot!

I really have forgot to make it a response!!!

Thank you Matt!

Brane