Desktop version

Main > Forum > 1C:Enterprise Platform > Studying 1C:Enterprise platform > Delete a selection from query

Forum

Search UsersRules
Delete a selection from query
#1
Active user
Points:: 0
Joined:: Jun 4, 2013

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

Profile
#2
Active user
Points:: 0
Joined:: Sep 26, 2012

try so

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

Profile
#3
Active user
Points:: 0
Joined:: Jun 25, 2013

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;

Profile
#4
Active user
Points:: 0
Joined:: Jun 4, 2013

Thanks it worked

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.