Append Item Value

Hi All,

I have two databases A&B, which contains 5 docs in A db and 1 doc in B db. Can some body tell me how to compare both docs item values (Price filed) and append other 4 Price entries in B db doc from A db docs. It is very urgent.

Thanks in Advance

Subject: Append Item Value

Start by thinking through the problem. Then you break it down into smaller steps. Finally you write the actual code.

Next time you have a question, please think through the problem, and post the code you have written this far. You should also write a more detailed specification, your explanation above indicates that only the price is compared. What happens if two items have the same price? Or if database B have more documents than database A?

Things like that is what you need to think about, as a programmer.

Below is how I would solve it, but there are probably several other solutions. Note that this solution depends on the assumption that not two items have the same price, which is how your description explains it. If you want to compare another field (it would for example probably make sense to use a unique product id), just modify the algorithm below.

  • Get a collection of documents from database A that you want to check (5 docs)

  • Create a list of NotesDocuments from that collection, with the price as list tag.

  • Get a collection of documents from database B that you want to check (1 docs)

  • Create another list of NotesDocuments, from the collection from database B, with the price as list tag.

  • Use a ForAll loop to process all list items in your first list. Use IsElement() to check if the same list tag is present in the other list. [1]

  • If the same list tag is not present in list B, copy the document from db A to db B.

[1] Something like this:

ForAll a in ListA

If IsElement(ListB(ListTag(a))) = False Then

'*** Copy document from db A to db B

Set doc = dbA.GetDocumentByUNID(a)

Call doc.CopyToDatabase(dbB)

End If

End Forall