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

Documents

1C:Enterprise script objects used for operations with documents

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

Quick developer reference / Documents / 1C:Enterprise script objects used for operations with documents
Fig. 29.5. 1C:Enterprise script objects used for operations with documents

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, while the target object of the arrow is the type of returned object.

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 documents that involve 1C:Enterprise script objects, see listing 29.6.

Listing 29.6. Object usage examples 

1.  // Global context
    // Documents
 
// Example: displaying all types of references to documents available in the configuration.
Array = Documents.AllRefsType().Types();
For Each NextType In Array Do
    Message(NextType);
EndDo;
 
2.  // DocumentsManager object
    // .<document name>
    // [<document name>]
    // For Each … In … Do … EndDo;
 
// Example: getting the print template for the Services document
Template = Documents["Services"].GetTemplate("Print");
 
// Example: getting references for all documents available in the configuration.
For Each NextDocument In Documents Do
    Ref = NextDocument.GetRef();
    …
EndDo;
 
3.  // DocumentManager.<document name> object
    // FindByNumber()
    // FindByAttribute ()
    // EmptyRef ()
 
// Example: checking whether the GoodsReceipt document #3 has been posted.
If Documents.GoodsReceipt.FindByNumber(3).Posted Then
    Message("Document #3 is posted.");
EndIf;
 
// Example: checking whether the Warehouse attribute is filled
// in all GoodsReceipt documents.
WarehouseEmptyRef = Catalogs.Warehouses.EmptyRef();
If Not Documents.GoodsReceipt.FindByAttribute("Warehouse",WarehouseEmptyRef).IsEmpty() Then
    Message("Documents with blank Warehouse attribute are found.");
EndIf;
 
4.  // DocumentManager.<document name> object
    // Select()
 
// Example: selecting all GoodsReceipt documents for the current month.
Selection = Documents.GoodsReceipt.Select(BegOfMonth(CurrentDate()), EndOfMonth(CurrentDate()));
While Selection.Next() Do
    Message(Selection);
EndDo;
 
5.  // DocumentManager.<document name> object
    // CreateDocument()
 
// Example: creating a GoodsReceipt document.
NewDocument = Documents.GoodsReceipt.CreateDocument();
NewDocument.Date = CurrentDate();
NewDocument.Warehouse = Catalogs.Warehouses.Main;
// Filling the Materials tabular section
NewTableRow = NewDocument.Materials.Add();
NewTableRow.Material = Catalogs.MaterialsAndServices.FindByCode(6);
NewTableRow.Quantity = 10;
NewTableRow.Price = 22.5;
NewTableRow.Total = 225;
NewDocument.Write();
 
6.  // DocumentObject.<document name> and DocumentRef.<document name> objects
    // Ref
 
// Example: calling a procedure within an object module to check
// whether document attributes are filled.
If Not CheckAttributesFilling(ThisObject.Ref) Then
    Message("Document attributes are not filled.");
EndIf;
 
7.  // DocumentRef.<document name> and DocumentObject.<document name> objects
    // GetObject()
    // Copy()
 
// Example: marking a document for deletion.
OldDocument = Documents.Services.FindByNumber(13).GetObject();
OldDocument.SetDeletionMark(True);
 
8.  // DocumentSelection.<document name> object
    // Ref
 
// Example: generating a list of references to all GoodsReceipt documents for the current month.
ReceiptList = New ValueList;
Selection = Documents.GoodsReceipt.Select(BegOfMonth(CurrentDate()),
EndOfMonth(CurrentDate()));
While Selection.Next() Do
    ReceiptList.Add(Selection.Ref);
EndDo;
 
9.  // DocumentSelection.<document name> object
    // GetObject()
 
// Example: deleting all GoodsReceipt documents.
Selection = Documents.GoodsReceipt.Select();
While Selection.Next() Do
    Selection.GetObject().Delete();
EndDo;

Event sequence for writing documents from document forms

Quick developer reference / Documents / Event sequence for writing documents from document forms
Fig. 29.6. Event sequence for writing a new document from a document form

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

Event sequence for posting documents from document forms (post and close)

Quick developer reference / Documents / Event sequence for posting documents from document forms (post and close)
Fig. 29.7. Event sequence for posting a document from a document form

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

Event sequence for canceling document posting from document forms

Quick developer reference / Documents / Event sequence for canceling document posting from document forms
Fig. 29.7. Event sequence for canceling document posting from a document 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