Is it going to have two documents?

Hello,

I was confusing with the coding below. After running the coding, are there two documents with the same UniversalID in the view which are userdoc & newdoc?

Thanks,

Linda

Set newdoc = userdb.CreateDocument

Call userdoc.CopyAllItems(newdoc)

newdoc.Form=“(frmCMView)”

newdoc.CMUnique=userdoc.UniversalID

Call newdoc.Save(False, False)

Call ws.EditDocument(False, newdoc)

Subject: is it going to have two documents?

What field/formula are you displaying in the view?

Is the Univeral ID the same or do the docs share a field value CMUnique (which could be the UNID value but is NOT the UNID of the docs).

In other words, if you look at the doc properties, do they have the same UNID?

Doug

Subject: RE: is it going to have two documents?

Hi Doug, The field CMUnique in the form contails the formula with @DocumentUniqueID, here assign the UNID to it, I think it will be the same for the UNID and the UNID of the document. if it is the same. means there is only one document, am I right?

Thanks,

Linda

Subject: RE: is it going to have two documents?

No, you have two documents. You can’t have more than one document with the same UniversalID, but you can have as many documents as you want containing fields (aka NotesItems) with the same value. It doesn’t matter at all that the value happens to be the UniversalID of some other document.

I.e., you end up with two documents:

Doc1:

UniversalID= 111111112222222223333333344444444

CMUnique= 111111112222222223333333344444444

Doc2:

UniversalID= 555555556666566667777777788888888

CMUnique= 111111112222222223333333344444444

Subject: …but that second document might get the CMUnique changed if the document is reseved from the GUI

If CMUnique is a completed field, then when the new document if opened by a user, it’s value will be reset to the UNID of the document.

If I may venture a guess, the intent may be to have the CMUnique be set to UNID of the new document, instead of the document being copied. (Otherwise, the CopyAllFields would have already done that) If that’s the case, your code is incorrect, and needs to be re-worked. Also, the new document must be saved first, as it does not have an UNID until then.

Subject: RE: …but that second document might get the CMUnique changed if the document is reseved from the GUI

Hi Graham, Yes, I am trying to fix a problem that is the ReferralID doesn’t match that of the active initial referral, which causes the menu to display the wrong set of documents for creation.

if possible can I ask the details to fix the problem? how to re-worked to keep the same UNID for creating (inherit/edit) document later on? the coding is below.

Thanks a lot.

linda

Sub Click(Source As Button)

On Error Resume Next

Dim session As New NotesSession, db As NotesDatabase, doc As NotesDocument

Dim ws As New NotesUIWorkspace, uidoc As NotesUIDocument

Dim ndbAdmin As NotesDatabase, ndbSummary As NotesDatabase

Dim nvSummary As NotesView, nvAdmin As NotesView

Dim ndSummary As NotesDocument, ndAdmin As NotesDocument, ndDelete As NotesDocument, ndTemp As NotesDocument

Dim userdb As NotesDatabase, userview As NotesView, userdoc As NotesDocument

Dim newdoc As NotesDocument

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

If dc.Count = 0 Then Msgbox "Select a Case Record first." : Exit Sub

If dc.Count > 1 Then Msgbox "Only Select 1 Case Record." : Exit Sub



Set doc = dc.GetFirstDocument

theserver = db.Server

thepath = doc.thepath(0)

Set userdb = session.GetDatabase(theserver, thepath)

If userdb.Title="" Then

	'get summary, doc

	Set ndbSummary = session.GetDatabase(theserver, "IFRs\MCSSSummary.nsf")

	Set nvSummary = ndbSummary.GetView("(sumbyub)")

	Set ndSummary = nvSummary.GetDocumentByKey(doc.UniqueBind(0))

	If ndSummary Is Nothing Then

		Msgbox "Case cannot be located. Please contact the Help Desk. Error 139"

	Else

		Set userdb = session.GetDatabase(theserver, ndSummary.thepath(0))

		If userdb.Title="" Then

			Msgbox "User database cannot be located. Please contact the Help Desk. Error 149"

		Else

			Set userview = userdb.GetView("(vwAllCM)")

			Set userdoc = userview.GetDocumentByKey(doc.UniqueBind(0))

			If userdoc Is Nothing Then

				Msgbox "Case cannot be located. Please contact the Help Desk. Error 169"

			Else

				Set newdoc = userdb.CreateDocument

				Call userdoc.CopyAllItems(newdoc)

				newdoc.Form="(frmCMView)"

				newdoc.CMUnique=userdoc.UniversalID

				newdoc.SummaryHide="1"

				Call newdoc.Save(False, False)

				Call ws.EditDocument(False, newdoc)

’ Call ws.EditDocument(False, userdoc)

			End If

		End If

	End If

Else

	If Not userdb.Title="" Then

		Set userview = userdb.GetView("(vwAllCM)")

		Set userdoc = userview.GetDocumentByKey(doc.UniqueBind(0))

		If userdoc Is Nothing Then

			Set ndbSummary = session.GetDatabase(theserver, "IFRs\MCSSSummary.nsf")

			Set nvSummary = ndbSummary.GetView("(sumbyub)")

			Set ndSummary = nvSummary.GetDocumentByKey(doc.UniqueBind(0))

			If ndSummary Is Nothing Then

				Msgbox "Case cannot be located. Please contact the Help Desk. Error 169"

			Else

				Set userdb = session.GetDatabase(theserver, ndSummary.thepath(0))

				If userdb.Title="" Then

					Msgbox "User database cannot be located. Please contact the Help Desk. Error 179"

				Else

					Set userview = userdb.GetView("(vwAllCM)")

					Set userdoc = userview.GetDocumentByKey(doc.UniqueBind(0))

					If userdoc Is Nothing Then

						Msgbox "User database cannot be located. Please contact the Help Desk. Error 199"	

					Else

						Set newdoc = userdb.CreateDocument

						Call userdoc.CopyAllItems(newdoc)

						newdoc.Form="(frmCMView)"

						newdoc.CMUnique=userdoc.UniversalID

						newdoc.SummaryHide="1"

						Call newdoc.Save(False, False)

						Call ws.EditDocument(False, newdoc)							

						'Call ws.EditDocument(False, userdoc)		

					End If

				End If

			End If

		Else

			Set newdoc = userdb.CreateDocument

			Call userdoc.CopyAllItems(newdoc)

			newdoc.Form="(frmCMView)"

			newdoc.CMUnique=userdoc.UniversalID

			newdoc.SummaryHide="1"

			Call newdoc.Save(False, False)

			Call ws.EditDocument(False, newdoc)

			'Call ws.EditDocument(False, userdoc)

		End If

	End If

End If

End Sub

Subject: RE: is it going to have two documents?

I see. thanks Richard.

Hi Graham,

Yes, I am trying to fix a problem that is the ReferralID doesn’t match that of the active initial referral, which causes the menu to display the wrong set of documents for creation.

Can I ask the details to fix the problem? how to re-worked to keep the same UNID for creating (inherit/edit) document later on?

Thanks a lot.

linda

Linda

Subject: RE: is it going to have two documents?

I’m confused. If you see Richard’s point, then you should understand that each document in a replica gets a new UNID so yoiu cannot share UNID’s across documents.

If you want a field in multiple docs that inherits some value, then just set the value in your first document and then copy/inherit into all subsequent docs related to it.

For example:

First doc created has some system assigned UNID.

Create a field ‘MyUNID’ and set it to @Text(@DocumentUniqueID) - @function may be wrong, I’m not at my PC right now but there is an @Function to get the UNID.

If you copy all items to a new doc based on the first one, then MyUNID in all subsequent copies will be whatever it was in the first doc created.

Stepping outside this conversation, what are you trying to accomplish? It might help if we understood what you need so we might suggest other ways to accomplish the required outcome.

Doug

Subject: RE: is it going to have two documents?

Hi Doug, Thank you so much for your help.

The thing is this application was designed by someone else, now we found a bug which is creating a new document is incorrect, the new document inherit values form a unknow document instead of the original one. I am trying to fix it.

I see your point, I will let you know how’s it going.

Many thanks for your time and kindness.

Linda