1C:Enterprise 8.3. Practical Developer’s Guide. Quick developer reference. Catalogs


1C:Enterprise script objects used for operations with catalogs

The following chart shows the interaction between 1C:Enterprise script objects used for operations with catalogs (fig. 29.3).

Quick developer reference / Catalogs / 1C:Enterprise script objects used for operations with catalogs
Fig. 29.3. 1C:Enterprise script objects used for operations with catalogs

Note. The yellow box indicates the data manipulation object. The object method from which the arrow originates is marked with the respective number in the listing (for example, number 3 stands for the FindByCode() method of the CatalogManager.<name> object), while the target object of the arrow is the type of returned object (for example, CatalogRef.<name>).

Learn more! For details on major types of 1C:Enterprise script objects, see section 1C:Enterprise script objects used for operations with applied data.

For examples of operations with catalogs that involve 1C:Enterprise script objects, see listing 29.5.

Listing 29.5. Object usage examples 

1.  // Global context
    // Catalogs
// Example: displaying all types of references to catalog items available in the configuration.
Array = Catalogs.AllRefsType().Types();
For Each NextType In Array Do
2.  // CatalogsManager object
    // .<catalog name>
    // [<catalog name>]
    // For Each … In … Do … EndDo;
// Example: creating a folder in the MaterialsAndServices catalog.
NewFolder = Catalogs.MaterialsAndServices.CreateFolder();
NewFolder.Description = "My new folder";
// Example: getting a reference to the MaterialsAndServices catalog.
3.  // CatalogsManager.<catalog name> object
    // FindByCode()
    // FindByDescription()
    // FindByAttribute()
    // EmptyRef()
    // GetRef()
    // .<predefined catalog item name>
// Example: checking whether a MaterialsAndServices catalog item with code 13
// is marked for deletion.
If Catalogs.MaterialsAndServices.FindByCode(13).DeletionMark Then
    Message("Item with code 13 is marked for deletion.");
// Example: checking whether a MaterialsAndServices catalog item named "Services"
// is a folder.
If Catalogs.MaterialsAndServices.FindByDescription("Services", True).IsFolder Then
    Message("The item named Services is a folder.");
// Example: checking whether all catalog items have a type (material or service).
EmptyEnumRef = Enums.MaterialServiceTypes.EmptyRef();
If Not Catalogs.MaterialsAndServices.FindByAttribute("ProductType", EmptyEnumRef).IsEmpty() Then
    Message("Items with no type assigned are found.");
// Example: passing an empty reference to a method parameter.
Selection = Catalogs.MaterialsAndServices.Select(Catalogs.MaterialsAndServices.EmptyRef());
4.  // CatalogManager.<catalog name> object
    // Select()
    // SelectHierarchically()
// Example: displaying the list of items located in the root folder of the catalog.
Selection = Catalogs.MaterialsAndServices.Select(Catalogs.MaterialsAndServices.EmptyRef());
While Selection.Next() Do
    If Not Selection.IsFolder Then Message(Selection);
// Example: deleting all items from a hierarchical catalog.
Selection = Catalogs.MaterialsAndServices.SelectHierarchically();
While Selection.Next() Do
5.  // CatalogManager.<catalog name> object
    // CreateFolder()
    // CreateItem()
// Example: creating an item in the Employees catalog.
NewItem = Catalogs.Employees.CreateItem();
NewItem.Description = "Andrew A. Smith";
// Filling the PastEmployment tabular section.
NewTableRow = NewItem.PastEmployment.Add();
NewTableRow.Company = "NTC Corp.";
NewTableRow.StartDate = Date(2013,05,01);
NewTableRow.EndDate = Date(2013,12,31);
NewTableRow.JobTitle = "Programmer";
6.  // CatalogObject.<catalog name> and CatalogRef.<catalog name> objects
    // Owner
    // Parent
    // Ref
// Example: prohibiting changes to subordinate items in the catalog item form module
// if the ProhibitChanges property of the owner item is True.
Procedure BeforeWrite(Cancel)
    If Owner.ProhibitChanges Then Cancel = True;
7.  // CatalogRef.<catalog name>
    // GetObject()
    // CatalogObject.<catalog name>
    // Copy()
// Example: changing catalog item name.
Item = Catalogs.MaterialsAndServices.FindByCode(10).GetObject();
Item.Description = "My new description";
// Example: filling a catalog with test data.
Item = Catalogs.MaterialsAndServices.CreateItem();
Item.Description = "Test item";
For Z = 1 To 1000 Do
    NewItem = Item.Copy();
8.  // CatalogSelection.<catalog name> object
    // Ref
// Example: filling the tabular section of a GoodsReceipt document
// with all the items from the specified MaterialsAndServices catalog folder.
Selection = Catalogs.MaterialsAndServices.SelectHierarchically(TextBox1);
While Selection.Next() Do
    MaterialOrServiceReference = Selection.Ref;
    If MaterialOrServiceReference.IsFolder Then Continue;
    NewRow = Materials.Add();
    NewRow.Material = MaterialOrServiceReference;
9.  // CatalogSelection.<catalog name> object
    // GetObject()
// Example: marking all items of a nonhierarchical catalog for deletion.
Selection = Catalogs.Customers.Select();
While Selection.Next() Do

Event sequence for writing catalog items from item forms (save and close)

Quick developer reference / Catalogs / Event sequence for writing catalog items from item forms (save and close)
Fig. 29.4. Event sequence for writing a catalog item from an item form

Note. Yellow boxes indicate events executed in the writing transaction.

Leave a Reply

Your email address will not be published. Required fields are marked *

1C:Enterprise Developer's Community