Child Request Nos and Closing of Child Requests

I have a form for “SAP Request” which has 2 buttons , “ABAP Request” and “Basis Request”.When “ABAP Request” is clicked , a form “ABAP” opens and when “Basis Request” is clicked , a form “Basis” opens.

“SAP Request” form has a field “child_id” which is set whenever “ABAP Request” or “Basis Request” button is clicked.Both of the child forms also has a field “child_id” which is inherited from Parent form.

The code which I use for setting chilld_id whenever “ABAP Request” or “Basis Request” button is clicked is as follows:

Sub Click(Source As Button)

Dim w As New NotesUIWorkspace

Dim session As New NotesSession	

Dim db As NotesDatabase

Dim view As NotesView	

Dim vc As NotesViewEntryCollection

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim counterdoc As NotesDocument

Dim itemA As NotesItem

Dim notesForm As NotesForm

Dim doc1 As  Notesdocument

Dim collection As NotesDocumentCollection

Dim currentResponse As NotesDocument

Dim i As Integer



Set db = session.CurrentDatabase	

Set uidoc = w.CurrentDocument

Set doc = uiDoc.Document

Set doc1 = db.CreateDocument



Set collection = doc.Responses

Set currentResponse = collection.GetFirstDocument



i = doc.Responses.Count + 1



Call uidoc.FieldSetText("child_id",uidoc.FieldGetText("id") + " - " + Cstr(i))



Call uidoc.FieldSetText("fd_modified_date",Cstr(doc1.Created))

Call w.ComposeDocument( "", "", "Form" )





Call uidoc.Save

unid = doc.UniversalID

doc.SaveOptions = "0"



Call doc.Save(False, True)	



Call uidoc.close

End Sub

Id is the counter of the “SAP Request” form.

The problem which I have is that whenever a new child is created , child_id value should be “id - 1”,and so on but it always shows "id - " when first time “ABAP Request” or “Basis Request” button is clicked.some times , 3rd or 4th child is created but it shows the id value as “id-5”.

2nd problem is that “SAP Request” form has a button “Close Request” which should be enabled only when all child request have been closed.I have “rwfdocstatus” field on both the child forms and I use the following code to check the child request status.if the status is “Request Closed” for all child requests , “Close Request” button is enabled.

Sub Click(Source As Button)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim collection As NotesDocumentCollection

Dim currentResponse As NotesDocument

Dim i As Integer

Dim check As Integer



Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

Set collection = doc.Responses

Set currentResponse = collection.GetFirstDocument



Call doc.PutInFolder( "child docs" )

’ Put immediate responses to doc into the folder

’ If there are none, sub exits and returns to calling sub

check = 0



For i = 1 To doc.Responses.Count

	Call currentResponse.PutInFolder("child docs" )		

	If (currentResponse.rwfdocstatus(0) = "Request Closed")  Then

		check = check + 1 

	End If

	Set currentResponse = collection.GetNextDocument _

	( currentResponse )

Next





If(check = doc.Responses.Count) Then

	Call uidoc.FieldSetText("x_fd_statusN" ,"8.5")

End If



savcheck=1

Call uidoc.Save

unid = doc.UniversalID

doc.SaveOptions = "0"



Call doc.Save(False, True)	



Call uidoc.close

End Sub

The issue is that it works properly only when there is no child.If requests have childs , it does not enable “Close Requests” when all child requests have been closed.Some times , it creates another copy of same “SAP Request” and enable “Close Request” button in that copied form.

Kindly tell me what are the issues behind this?

Regards,

Aisha Ishrat.

Subject: Child Request Nos and Closing of Child Requests

Hello Aisha,

Big Questions for small problems :).

For first problem:

Instead of using:

Call uidoc.FieldSetText(“child_id”,uidoc.FieldGetText(“id”) + " - " + Cstr(i))

use backend document handle:

uidoc.document.child_id = uidoc.document.id(0) + " - " + Cstr(i)

or

uidoc.document.child_id = uidoc.FieldGetText(“id”) + " - " + Cstr(i)

For second problem:

I am not sure why you are putting all document in folder. Describe more.

Subject: RE: Child Request Nos and Closing of Child Requests

let me try your proposed solution for the first issue.

2nd issue:

I am putting the current doc and its all child docs in a folder not for this functionality but for some other purpose.I dont think that this causes some effect on this code.What you say?

Thanks.

Aisha Ishrat

Subject: RE: Child Request Nos and Closing of Child Requests

ok got it.

well for second, I believe there must be some Hide When formula for Close Request (as you said Close Request button enabled)

What I think is on your Close Request button on SAP Request form, loop through all child document and if any child status is not yet closed, ask user to close it before closing the SAP Request and remove any Hide When formula so that it remains available all the time but restrict user to clsoe the parent if any of the child status is open.

The possible cause for Copy SAP Request document is that when you are closing child document you might be modifiing Parent document as well and if Parent document is open in notes client it will create another copy. But this is one possibility they could be other as well.

Subject: RE: Child Request Nos and Closing of Child Requests

uidoc.document.child_id = uidoc.document.id(0) + " - " + Cstr(i)

or

uidoc.document.child_id = uidoc.FieldGetText(“id”) + " - " + Cstr(i)

The above statements have the same issues.

Subject: RE: Child Request Nos and Closing of Child Requests

move the statement:

Call w.ComposeDocument( “”, “”, “Form” )

after this statement:

Call doc.Save(False, True)

should work. reason is that parent document is not saved and you are creating child doucment which is using fields from Parent. If parent is not saved, child will not show correct values.

Subject: RE: Child Request Nos and Closing of Child Requests

issue # 1: your last suggestion works.issue # 2: the point which i observed after testing is that i have an emebeded view in SAP form for all child requests,If i opens child requests from that view and process further , only then it creates a copy and does not work for “Close Request” button, if i process the child docs after opening it from some other view then it works properly and no copy creates, same thing you told me.

Thanks a lot for your help & spending your time.

Kind Regards,

Aisha Ishrat.