Delete a selection from query

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: Jun 4, 2013
Company:

hi I'm trying to delete a specific catalog item ... I thought it will work out if i use queries ... so i wrote :

Code
   Query = New Query;
   Query.Text = "SELECT * FROM catalog.second"  ;
   Selection = Query.Execute().Choose();
   
        while Selection.Next() do
   
          if String(selection.company)="" then
   
   // **HERE I WANT DO DELETE THIS SELECTION**
   
     endif;
      
   enddo ;

if anyone can help me with this I'll bee Thankful

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

try so

Code
if String(selection.company)="" then
   
   selection.Ref.GetObject().Delete();
   
endif;

 
#3
People who like this:1Yes/0No
Active user
1C:Professional
Rating: 8
Joined: Jun 25, 2013
Company: 1C Company

Please pay attention to the following recommendations:

1) Always include selection conditions in a query when it is possible.
2) Mark objects for deletion instead of deleting them directly and then delete them with the "Marked object deletion" data processor. It helps you to keep you data integrity.

Here is your example:

Code
   Query = New Query;
   Query.Text =
   "SELECT
   |   *
   |FROM
   |   Catalog.Second AS SecondCatalog
   |WHERE
   |   SecondCatalog.Company = VALUE(Catalog.Companies.EmptyRef)";
   // If Company is a value of Catalog.Companies type 

   Selection = Query.Execute().Choose();
   
   While Selection.Next() do
   
      SelectedObject = Selection.Ref.GetObject();
      SelectedObject.DeletionMark = True;
      SelectedObject.Write();
      
   Enddo;

1C Company support team
 
#4
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

Thanks it worked

 
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.