How to delete rows from the tabular section?

Understanding basics of 1C:Enterprise platform. To start working with 1C:Enterprise platform visit Getting started page

#1
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Sep 27, 2011
Company:

Hi!

I need to add a command which removes services from the document tabular section, here is my code:

Code
   For Each Row In Object.Goods Do
      If Row.Item.Type = Enums.ItemTypes.Service Then
         Object.Goods.Delete(Row.LineNumber - 1);
      EndIf;
   EndDo;

It works, but sometimes not all lines are deleted.

Edited: Eric Kruger - Oct 04, 2012 11:22 AM
 
#2
People who like this:0Yes/0No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

I think you need begin delete rows from end :)
Try this:

Code
countRows = Object.Goods.Count();
For i = 1 to countRows Do
  Row = Object.Goods[countRows - i];
  If Row.Item.Type = Enums.ItemTypes.Service Then
     Object.Goods.Delete(Row.LineNumber - 1);
  EndIf;
EndDo;

 
#3
People who like this:0Yes/0No
Just came
Rating: 0
Joined: May 5, 2012
Company:

The problem occur when rows ,that is needed to delete, stand in line one by one, because quantity of tabular section decreases on 1 but operator "For Each" continues to work with old indexes and skips row that is needed to delete but it's behind current iteration.
You can overcome this problem like this:

Code
DeleteRow = True;
While DeleteRow Do
   For Each Row In Object.Goods Do
      If Row.Item.Type = Enums.ItemTypes.Service Then
         Object.Goods.Delete(Row.LineNumber - 1);
       DeleteRow = True;
         Continue;
     Else 
       DeleteRow = False;
      EndIf;
   EndDo;
EndDo;

Edited: Bogdan Sinitsa - Oct 04, 2012 12:02 PM
 
#4
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Sep 27, 2011
Company:

Wery smart idea to delete them from behind, who could guess? Thanks, ivan!
Interesting idea, Bogdan Sinitsa

Edited: Eric Kruger - Oct 04, 2012 01:42 PM
 
#5
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

I was trying to delete a raw  from a different catalog but I couldn't .... do you have any idea to do that ?!

I tried like this but it didnt work

Code
  a=Catalogs.Workers.FindByDescription("kamil namli").GetObject().workersTable ;
      for each i in a do
       i.delete(i.LineNumber-1);
      enddo


there is no delete method when you use  FindByDescription :S

thanks in advance :)

 
#6
People who like this:0Yes/0No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

try so:

Code
a=Catalogs.Workers.FindByDescription("kamil namli").GetObject();
for each i in a.workersTable do
  a.workersTable.delete(i);
enddo;

a.Write();


In your example method "delete" used to "i", where "i" is line of a tabular section. But this method applied to tabular section.

Edited: ivan avdonin - Aug 20, 2013 02:19 AM
 
#7
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Nov 1, 2011
Company:

First of all, you should check if such an item exist.
Then loop from the end to begining.

Code
a=Catalogs.Workers.FindByDescription("kamil namli").GetObject();

If Not a=Undefined Then
    RowCount = a.workersTable.Count();
    For i=1 to RowCount do
        a.workersTable.Delete(RowCount-i);
    EndDo;
    a.Write();
EndIf;


And after all, if you want to delete all rows you should use Clear() method.

Code
a=Catalogs.Workers.FindByDescription("kamil namli").GetObject();

If Not a=Undefined Then
    a.workersTable.Clear();
    a.Write();
EndIf;

Edited: Alexey Alexandrovich - Aug 21, 2013 12:37 AM
 
#8
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

thanks a lot  .. and no I don't want to delete all the rows ... the delete method has worked perfectly

 
#9
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Nov 1, 2011
Company:

Hi!
You have to create an array, fill it with rows to be deleted.
Then, in a loop around the array and calls the tables of Delete, as a parameter to pass an array element.

 
#10
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Nov 1, 2011
Company:

Example:

Code
DeleteRows = New Array;

For Each Row In Object.Goods Do
   If Row.Item.Type = Enums.ItemTypes.Service Then
      DeleteRows.Add(Row);    
   EndIf;
EndDo;

For Each DelRow In DeleteRows  Do
   Object.Goods.Delete(DelRow);
EndDo;

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.