on 04-07-2024 1:20 AM
Hi,
I need to some rows from product tree. Because I have Item rows and Resource rows. I want to delete only ITEM rows below code:
If vProdTree.GetByKey(agacKod) Then
For i As Integer = 0 To vProdTree.Items.Count - 1
vProdTree.Items.SetCurrentLine(i)
If vProdTree.Items.ItemType = SAPbobsCOM.ProductionItemType.pit_Item Then
Try
vProdTree.Items.Delete()
Catch ex As Exception
Console.WriteLine("Detay silinmedi? " & ex.Message & "--" & vCmp.GetLastErrorDescription & "-" & vCmp.GetLastErrorCode)
End Try
End If
Next
If vProdTree.Update() = 0 Then
Console.WriteLine(agacKod & " güncellendi...")
Else
MsgBox("Ürün ağacı detayı silinemedi!" & Chr(13) & "Sistem cevabı: " & vCmp.GetLastErrorDescription & "-" & vCmp.GetLastErrorCode, MsgBoxStyle.Critical, "Hata!")
Exit Sub
End If
End If
But I think when I delete row, index is changing in " vProdTree.Items.Count - 1" then I am getting error "Invalid Row"?!
How can I solve it?
Regards,
Mucip:)
Hi mucipilbuga,
Yes, the index will be changed.
In my opinion, you should start from the last row. The following should work fine:
SAPbobsCOM.ProductTrees oPTs = (SAPbobsCOM.ProductTrees)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductTrees);
oPTs.GetByKey("A00001");
for (int i = oPTs.Items.Count - 1; i >= 0; i--)
{
oPTs.Items.SetCurrentLine(i);
var ItemCode = oPTs.Items.ItemCode;
if (oPTs.Items.ItemType == ProductionItemType.pit_Resource)
{
oPTs.Items.Delete();
}
}
Hope it helps!
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Ankit CHAUHAN,
Thanks a lot. I did not think like yours way. Really good.
But I did it my way like below 🙂 I decreased -1 on every delete step.
Dim sallamaKademe As Integer = 0
For i As Integer = 0 To vProdTree.Items.Count - 1
vProdTree.Items.SetCurrentLine(i - sallamaKademe)
Console.WriteLine(vProdTree.Items.ItemCode & " işleniyor... " & i)
If vProdTree.Items.ItemType = SAPbobsCOM.ProductionItemType.pit_Item Then
Try
vProdTree.Items.Delete()
sallamaKademe += 1
Catch ex As Exception
Console.WriteLine("Detay silinmedi? " & ex.Message & "--" & vCmp.GetLastErrorDescription & "-" & vCmp.GetLastErrorCode)
End Try
End If
Next
Regards,
Mucip:)
User | Count |
---|---|
95 | |
9 | |
8 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.