How to Delete cloned Item Relationship

オフライン
Hi Experts, I wrote a method in which I cloned Document type Item, which has 3 files attached(like Incoming.docx, Doc1.docx, Outgoing.docx). When I cloned an item, all these 3 attachments also there with the cloned document(obviously), Now I want to delete two files(i.e. Incoming.docx, Doc1.docx) and keep only one file (i.e Outgoing.docx). I tried 2 different scenarios, but I not able to delete those two attachments from the cloned Item. scenario 1: I attached only two files i.e (Incoming.docx and Outgoing.docx) when I cloned this document Item, and run AML which delete the last attached(i.e Incoming.docx) file to document but It won't work. scenario 2: I attached three files to the document and cloned that document then the error occurred: An entry with the same key already exists. Here is my code:
Dim inno as Innovator = getInnovator() Dim ItemId as String = Me.getProperty("item_number") Dim name as String = Me.getProperty("name") Dim docType as String = Me.getProperty("_document_type") Me.fetchRelationships("Document File") Dim rel1 as Item = Me.getRelationships("Document File") Dim count as Integer = rel1.getItemCount() Dim quotationMark as String = Chr(34) Dim k as Integer Dim clonedItem As Item = Me.clone(True) 'true for copy the relationships For k = 0 To count - 1 Dim DocFile as Item = rel1.getItemByIndex(k) clonedItem.addRelationship(DocFile) Next Dim classification as String = Me.getProperty("classification") Dim res2 as Item = clonedItem.apply() Dim clonedItemNumber as String = res2.getProperty("item_number") Dim ResultOnlyOutgoingDoc as Item = Nothing Dim i as Integer For i = 0 To count - 1 If i <> count - 1 Then Dim DocFile as Item = rel1.getItemByIndex(i) Dim whereDoc as String = "[Document].item_number='"+ clonedItemNumber + "' " Dim whereDoc_FILE as String = "[Document_FILE].sort_order='"+ i.ToString() + "' " Dim str as String = "<AML>" + "<Item type='Document' action='edit' where="+ quotationMark + whereDoc + quotationMark +" >" + "<Relationships>" + "<Item type='Document File' action='delete' where="+ quotationMark + whereDoc_FILE + quotationMark +"  >" + "</Item>" + "</Relationships>" + "</Item>" + "</AML>" res2 = inno.applyAML(str) End If Next Return res2
  Was my approach correct? or should I try something different? Thanks in advance, Regards, Maddy.