Show / Hide Table of Contents

    How to work with table fields

    Note

    Table fields available since DocuWare 7.1

    Note

    Tables are only supported for Store dialogs, Index dialogs and in Workflows.
    Tables cannot be added to search dialogs and content in tables can only be found through fulltext search.

    For File Cabinets there is now a new field type available. The field type is "Table".
    This field consists of several other fields and is displayed like a table.
    Table fields cannot be created during file cabinet creation.
    Supported field types for columns:

    • Text
    • Date
    • Decimal

    Upload a document including a table field

    Warning

    Table field columns right now case sensitive, this will change soon again!
    We are working on a fix

    public static Document UploadDocumentWithTableField(FileCabinet fc)
    {
    
    	var indexData = new Document
    	{
    		Fields = new List<DocumentIndexField>
    		{
    			//See separate method below
    			CreateTableField(),
    			DocumentIndexField
    				.Create("Company", "Home Improvement"),
    			DocumentIndexField
    				.Create("Contact", "Tim Taylor"),
    			DocumentIndexField
    				.Create("Subject", "Invoice from 12.04.2018"),
    			DocumentIndexField
    				.Create("DocumentNumber", "1337"),
    			DocumentIndexField
    				.Create("Date", new DateTime(2019, 4, 12)),
    			DocumentIndexField
    				.Create("DocumentType", "Invoice In")
    		}
    	};
    
    	//return uploaded document object
    	return fc.UploadDocument(indexData, new FileInfo("Invoice.pdf"));
    }
    
    private static DocumentIndexField CreateTableField()
    {
    	var todayInOneYear = DateTime.Today.AddDays(365);
    	return new DocumentIndexField()
    	{
    		FieldName = "InvoiceParts",
    		ItemElementName = ItemChoiceType.Table,
    		Item = new DocumentIndexFieldTable
    		{
    			Row = new List<DocumentIndexFieldTableRow>
    			{
    				// Table Fields are right now case sensitive!
    				// Please use exact same writing like in database.
    				// Bug will be resolved soon!
    
    				new DocumentIndexFieldTableRow()
    				{
    					ColumnValue = new List<DocumentIndexField>()
    					{
    						//prefix INVOI_ needed here (Database Name)
    						DocumentIndexField
    							.Create("INVOI_POSITION", 1m),
    						DocumentIndexField
    							.Create("INVOI_AMOUNT", 15.00m),
    						DocumentIndexField
    							.Create("INVOI_GOOD", "Saw"),
    						DocumentIndexField
    							.CreateDate("INVOI_WARRANTY", todayInOneYear)
    					}
    				},
    				new DocumentIndexFieldTableRow()
    				{
    					ColumnValue = new List<DocumentIndexField>()
    					{
    						//prefix INVOI_ needed here (Database Name)
    						DocumentIndexField
    							.Create("INVOI_POSITION", 2m),
    						DocumentIndexField
    							.Create("INVOI_AMOUNT", 5.99m),
    						DocumentIndexField.Create("INVOI_GOOD", "Hammer"),
    						DocumentIndexField
    							.CreateDate("INVOI_WARRANTY", todayInOneYear)
    					}
    				},
    				new DocumentIndexFieldTableRow()
    				{
    					ColumnValue = new List<DocumentIndexField>()
    					{
    						//prefix INVOI_ needed here (Database Name)
    						DocumentIndexField
    							.Create("INVOI_POSITION", 3m),
    						DocumentIndexField
    							.Create("INVOI_AMOUNT", 12.50m),
    						DocumentIndexField
    							.Create("INVOI_GOOD", "Screws"),
    						DocumentIndexField
    							.CreateDate("INVOI_WARRANTY", todayInOneYear)
    					}
    				}
    			}
    		}
    	};
    }
    

    Update a single value of table field column

    Note

    Tables cannot be retrieved in result lists.
    For manipulation of tables you need to get the full loaded document.

    public static DocumentIndexFields UpdateTableField(Document document)
    {
    	DocumentIndexField tableIndexField = document.Fields
    		.FirstOrDefault(f => f.FieldName == "InvoiceParts" 
    			&& f.ItemElementName == ItemChoiceType.Table);
    
    	if (tableIndexField != null && !tableIndexField.IsNull)
    	{
    		DocumentIndexFieldTable existingTableField = 
    			tableIndexField.Item as DocumentIndexFieldTable;
    
    		if (existingTableField?.Row.Count > 0)
    		{
    			DocumentIndexFieldTableRow documentIndexFieldTableRow =
    				existingTableField.Row.FirstOrDefault(r =>
    					r.ColumnValue
    						.Exists(c => c.FieldName == "INVOI_POSITION" 
    							&& (decimal)c.Item == 1m));
    
    			DocumentIndexField columnIndexFieldAmount =
    				documentIndexFieldTableRow?.ColumnValue
    					.FirstOrDefault(c => c.FieldName == "INVOI_AMOUNT");
    
    			if (columnIndexFieldAmount != null)
    			{
    				//Set for single entry a new price
    				columnIndexFieldAmount.Item = 30m;
    			}
    			else
    			{
    				//Use dedicated exception in production code!
    				throw new Exception("Column not found!");
    			}
    		}
    		else
    		{
    			//Use dedicated exception in production code!
    			throw new Exception("No table field rows available!");
    		}
    
    	}
    	else
    	{
    		//Use dedicated exception in production code!
    		throw new Exception("Table field does not exist!");
    	}
    
    	//Due to reference types we can just take the fields list
    	//from original provided document object
    	DocumentIndexFields updatedTableIndexFields = new DocumentIndexFields()
    	{
    		Field = document.Fields
    	};
    
    	//IMPORTANT: Send always ALL table fields to the server.
    	//Also in case only a single column value was updated,
    	//Otherwise all other table field entries get deleted!
    	return document.PutToFieldsRelationForDocumentIndexFields(updatedTableIndexFields);
    }
    
    About Us Contact Imprint Terms Data privacy
    © 2024 DocuWare Corporation powered by DocFX Back to top