--- pdfexport: true alias: tutorials-printabledocument timetoread: true tutorial: full description: "Printable Documents generate dynamic labels and documents based on data, ensuring traceability through versioning and printing options" --- # Using the Printable Document During the manufacturing process it may be necessary to print labels and documents. This can be achieved by using **Printable Document**. The **Printable Document** entity is the core object of Advanced Layout and Printing, which is the module that provides the ability to design and print labels, lot travelers and other types of documents, such as Material Identification or a Certificate of Conformance. !!! info Advanced Layout and Printing is a Critical Manufacturing optional module. This document provides step-by-step information so you can accomplish some common **Printable Document** scenarios. ## Overview The **Printable Document** represents a generic document whose content is generated dynamically whenever it is printed, based on a context that is a combination of user inputs and automatically calculated data (including serial numbers). It also ensures full traceability by versioning the **Printable Document** object and, optionally, keeping the history of each print operation including a preview of what was printed. The **Printable Document** is available for every object. ## Creating a Material Document This section describes how to create a simple document for a **Material**. The example will illustrate the usage of expressions and DEE Actions for calculating dynamic content. !!! info The procedure below is similar for every object type. The only difference is that for **Material**, printing can be initiated from the Material Details page, the Step View and the Resource View; for all other object types, the actual printing needs to initiated from the **Printable Document** details page. ### Configure the Printer Types 1. Add the different Printer Types to the Lookup table called *PrinterType*. 2. Configure the Smart Table *PrinterTypePrinterContexts*. This table maps the different Printer Types to specific Printers for particular users and computers. ![Configuring PrinterTypePrinterContexts][print_001] ### Configure the Necessary DEE Actions !!! info This is an optional step. The recommendation is to use DEE Actions only if it's not possible to achieve the same result using expressions or the expression editor of the layout designer. In this example, a simple action will be used to read the attribute *InspectionRate* of the Material and concatenate it with the *CustomerName* attribute of the **Material** **Product**. The Customer Name is associated with the non-versioned portion of the **Product**. ### Create the DEE Action Here is a DEE Action sample, called *PrintableDocumentGetInspectionRateAndCustomer*: ```csharp UseReference("Cmf.Foundation.BusinessObjects.dll", "Cmf.Foundation.BusinessObjects"); UseReference("Cmf.Navigo.BusinessObjects.dll", "Cmf.Navigo.BusinessObjects"); UseReference("Cmf.Foundation.BusinessOrchestration.dll", ""); UseReference("", "Cmf.Foundation.Common.Exceptions"); UseReference("", "Cmf.Foundation.Common"); IMaterial mat = Input["AppliesToValue"] as IMaterial; IProduct prod = mat.Product; //Load Attributes mat.LoadAttributes(new Collection() { "InspectionRate" }); prod.LoadAttributes(); Dictionary Output = new Dictionary(); Output["Result"] = String.Format("{0}% - {1}", mat.Attributes.ContainsKey("InspectionRate") ? mat.Attributes["InspectionRate"] : "", prod.RelatedAttributes.ContainsKey("CustomerName") ? prod.RelatedAttributes["CustomerName"] : ""); return Output; ``` To make the DEE Action available for **Printable Documents**, it's necessary to: 1. Define the Scope Classification for DEE actions by editing the Generic Table *ScopeClassifications* and creating an entry *PrintableDocumentContextItem* ![Defining ScopeClassification][print_002] 2. Create the DEE Action with the code specified above. ![Creating DEE Action][print_003] 3. When creating the DEE action (like the one with the source code example above), set its classification to the value defined in the previous point. ![Setting DEE Action Classification][print_004] 4. Create a **Rule** object with scope *PrintableDocumentContextItem* and referring to the entry created in point 1. ![Creating PrintableDocumentContextItem Rule][print_005] ### Create the Printable Document 1. Assuming that there is a **Change Set** created, create the **Printable Document**: ![Creating PrintableDocument object][print_006] 2. You can also edit the **Printable Document**: ![Setting PrintableDocument context - without rule][print_007] !!! note If your **Printable Document** is in the Created state, you will be able to edit more properties than when it is in the Effective state. ![Setting PrintableDocument context - with rule][print_008] !!! info For more information, see [Create Printable Document](../../../userguide/business-data/printable-document/create_printable_document.md) and [Edit Printable Document](../../../userguide/business-data/printable-document/edit_printable_document.md) in the User Guide. 3. Next, in the Layout designer, edit a page layout. You may reference any property of the `$AppliesToValue` entries or use the variables (PrimaryQuantity, FacilityName or TestLabel) that were used in this case. Be sure to save the layout before closing the layout editor. ![Editing the Page Layout][print_009] !!! info For more information on how to create and edit the page layout, see [Printable Document Layout Creation](../../../userguide/business-data/printable-document/printable_document_layout_creation.md) in the User Guide. ### Print the Document After setting the document effective, the document can be printed directly from the **Printable Document** details page. ![Printing the Printable Document][print_010] In order to be able to print the document directly from the **Material** (in alternative, from the Step View or Resource View), it's necessary to define the context in the Smart Table [MaterialPrintableDocumentContext](../../../userguide/administration/tables/smart-tables/materialprintabledocumentcontext.md). An example is shown in the next picture: ![Printing the Document from Material page][print_011] When selecting the **Print Documents** option, all **Documents** matching the document context will be available for the user. ## Printing a Lot Traveler The Lot Traveler is constructed dynamically based on the next **Steps** and **Flows** of the **Material**. !!! warning The Lot Traveler will print the **Material** current **Step** and all the next non-Optional, non-Alternate **Steps** for the **Area**. !!! warning If a **Step** of the **Area** does not have a Lot Traveler defined, the system will try to use the default Lot Traveler document from the Smart Table [AreaPrintableDocumentContext](../../../userguide/administration/tables/smart-tables/areaprintabledocumentcontext.md). If no default document exists, the **Step** will be skipped in the Lot Traveler printing. ### Create the Lot Traveler The creation process of a **Printable Document** suitable for being used in a Lot Traveler is similar to the creation of **Printable Document** as explained above with the particularity that, it must be of type "Lot Traveler". When a **Printable Document** is defined of type "Lot Traveler", the Applies To property is automatically set to Material. In addition, three Data Contexts are automatically created: **Step**, **Flow** and **Flow Path**. Because the Lot Traveler is based on dynamic information of the **Material**, during runtime, the system will supply the appropriate values for these three contexts for each **Step**. ### Associate the Lot Traveler with the Steps Each **Step** can have its own Lot Traveler document, or each **Step** can have its own unique Lot Traveler document. To associate a Lot Traveler with a **Step**, it's necessary to edit the **Step** and set the **Step** *Lot Traveler* property. For convenience, it's also possible to define the Lot Travelers for a complete **Area** or **Facility** in the Smart Table [AreaPrintableDocumentContext](../../../userguide/administration/tables/smart-tables/areaprintabledocumentcontext.md). An example is shown in the next picture: ![Link Area and PrintableDocument][print_012] To print the Lot Traveler (it always prints the Lot Traveler for the complete **Area**), it's just necessary to select the desired **Material** in the Step View, Resource View or in the **Material** details page, and then select **Print Lot Traveler**. ![Print Lot Traveler][print_013] !!! info By default, it only prints the Lot Traveler for all the current and next steps of the current **Area**. It's also possible to print the Lot Traveler for the current **Step** by selecting the *Current Step only* option on the right side of the Wizard or print the Lot Traveler for the all **Facilities** by selecting the All Facilities only option on the right side of the Wizard. !!! info More information on how to print a Lot Traveler or other **Material** documents can be found at [Print Material Documents](../../../userguide/business-data/material/print_material_documents.md) section of the User Guide. ## Additional Information ### Using Entity Types in a Printable Document **Printable Documents** can be created for any entity type by defining the desired entity type as *Applies To* property. A print button on the entity details page appears only for **Material** objects and documents to be printed for a given **Material** are resolved using the Smart Table [MaterialPrintableDocumentContext](../../../userguide/administration/tables/smart-tables/materialprintabledocumentcontext.md). For all other EntityTypes, printing has to be triggered from the **Printable Document** page. ### Linking a dynamic variable to a Entity Type property There are two possible options: 1. Define a ContextItem for which the value is an EntityInstance (Object) and in the Document designer, link the layout field values to the desired property of that object - when the value of a ContextItem is an **EntityType**, the designer will show all properties of that **EntityType**, so any property can be used. This is also applicable to the *AppliesTo* property, but in this case it appears as a parameter named `AppliesToValue` on the designer. 2. Define a ContextItem that uses an expression to extract the value of the desired property. In this case the designer will be provided with property value directly instead of the entire Entity Instance with all its different properties. The expression for this would be in the format: `$(ParameterName).(PropertyName)[.(PropertyName)...` where ParameterName is the name of the parameter holding the EntityInstance (may be another ContextItem or the `$AppliesToValue` special parameter) and (PropertyName) is the name of the desired property. !!! info If the *AppliesTo* refers to a **Material** object, you can dynamically get the **Facility** Name by creating a Context Item of type expression and specifying the source as `$AppliesToValue.Facility.Name`. ### Linking a variable to an entity type attribute In the case of attributes it becomes necessary to use a ContextItem that is calculated using a DEE Action since the Attributes must be loaded beforehand in order to be used. This would be a very simple DEE Action that just executes `LoadAttributes()` on the desired entity instance (possibly coming from another ContextItem or `$AppliesToValue`, as the DEE Action receives all values already calculated as input) and then returns the value of the desired attribute. ### String array support In order to support `string[]` types, the ContextItem would be defined as being of Type `String` and the *Value is Collection* flag must be set to True. Then the DEE Action that extracts the value of the attribute needs to convert the attribute value (which will be `List`) to a `Collection`. Example: ```csharp return new Collection(attrvalue as List); ``` [print_001]: ../../images/print_001.png [print_002]: ../../images/print_002.png [print_003]: ../../images/print_003.png [print_004]: ../../images/print_004.png [print_005]: ../../images/print_005.png [print_006]: ../../images/print_006.png [print_007]: ../../images/print_007.png [print_008]: ../../images/print_008.png [print_009]: ../../images/print_009.png [print_010]: ../../images/print_010.png [print_011]: ../../images/print_011.png [print_012]: ../../images/print_012.png [print_013]: ../../images/print_013.png