Update Index Fields
In order to update the values of the index fields of a document you only need to modify the changed fields. As a result of the update you get all fields returned.
As of DocuWare 7.8, the way that updating index fields is handled has been changed. By default, if a value has not changed, the system will not register it as such. By using the "ForceUpdate" flag, you can force the document to be treated as changed, even if no index fields actually changed.
Update some fields of a document
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static DocumentIndexFields Update(Document document)
{
var fields = new DocumentIndexFields()
{
Field = new List<DocumentIndexField>()
{
DocumentIndexField.Create("COMPANY", "Café Alt Wien"),
DocumentIndexField.Create("ORDER", "Some bags of Scarlatti Blend"),
DocumentIndexField.Create("AMOUNT", 37.98M), // Decimal value
DocumentIndexField.CreateDate("TOBEPAYED", DateTime.UtcNow + TimeSpan.FromDays(14)), // Just the day
DocumentIndexField.Create("INVOICERECEIVEDON", DateTime.UtcNow ), // Exact timestamp!
DocumentIndexField.Create("TAGS",
new DocumentIndexFieldKeywords() {
Keyword = new List<string>() { "Café", "Expensive", "Tasty" }
}),
DocumentIndexField.Create("NUMBEROFBAGS", 15) // integer value
}
};
return document.PutToFieldsRelationForDocumentIndexFields(fields);
}
}
}
Update some fields of a document asynchronously
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class ExamplesAsync
{
public static async Task<DocumentIndexFields> UpdateAsync(Document document)
{
var fields = new DocumentIndexFields()
{
Field = new List<DocumentIndexField>()
{
DocumentIndexField.Create("COMPANY", "Café Alt Wien"),
DocumentIndexField.Create("ORDER", "Some bags of Scarlatti Blend"),
DocumentIndexField.Create("AMOUNT", 37.98M), // Decimal value
DocumentIndexField.CreateDate("TOBEPAYED", DateTime.UtcNow + TimeSpan.FromDays(14)), // Just the day
DocumentIndexField.Create("INVOICERECEIVEDON", DateTime.UtcNow ), // Exact timestamp!
DocumentIndexField.Create("TAGS",
new DocumentIndexFieldKeywords() {
Keyword = new List<string>() { "Café", "Expensive", "Tasty" }
}),
DocumentIndexField.Create("NUMBEROFBAGS", 15) // integer value
}
};
return await document.PutToFieldsRelationForDocumentIndexFieldsAsync(fields).ConfigureAwait(false);
}
}
}
Force Update some fields of a document
C#
using DocuWare.Platform.ServerClient;
using System.Collections.Generic;
using System.IO;
using System.Runtime;
using System.Xml.Linq;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static void ForceUpdateIndexFields(Document document)
{
List<DocumentIndexField> fields = new List<DocumentIndexField>()
{
DocumentIndexField.Create("COMPANY", "Café Alt Wien"),
DocumentIndexField.Create("ORDER", "Some bags of Scarlatti Blend"),
};
var updateIndexFieldsInfo = new UpdateIndexFieldsInfo()
{
Field = fields,
ForceUpdate = false
};
//In this case if values of the fields match the existing ones, the update and audit for it will be skipped
document.PutToFieldsRelationForDocumentIndexFields(updateIndexFieldsInfo);
updateIndexFieldsInfo = new UpdateIndexFieldsInfo()
{
Field = fields,
ForceUpdate = true
};
//In this case if values of the fields match the existing ones, the update and audit for it will happen
document.PutToFieldsRelationForDocumentIndexFields(updateIndexFieldsInfo);
}
public static void ForceBatchUpdateIndexFields(FileCabinet fileCabinet)
{
List<int> documentIds = new List<int>()
{
1, 2, 3, 4
};
List<DocumentIndexField> fields = new List<DocumentIndexField>()
{
DocumentIndexField.Create("COMPANY", "Café Alt Wien"),
DocumentIndexField.Create("ORDER", "Some bags of Scarlatti Blend"),
};
var batchUpdateProcess = new BatchUpdateProcess
{
Data = new BatchUpdateProcessData
{
Field = fields,
ForceUpdate = false
},
Source = new BatchUpdateDocumentsSource
{
Id = documentIds
}
};
//In this case if values of the fields match the existing ones, the batch update and audit for it will be skipped
fileCabinet.PostToBatchUpdateRelationForBatchUpdateIndexFieldsResult(batchUpdateProcess);
batchUpdateProcess = new BatchUpdateProcess
{
Data = new BatchUpdateProcessData
{
Field = fields,
ForceUpdate = true
},
Source = new BatchUpdateDocumentsSource
{
Id = documentIds
}
};
//In this case if values of the fields match the existing ones, the batch update and audit for it will happen
fileCabinet.PostToBatchUpdateRelationForBatchUpdateIndexFieldsResult(batchUpdateProcess);
}
public static void ForceUpdateBatchAppendKeywordIndexFields(FileCabinet fileCabinet)
{
List<int> documentIds = new List<int>()
{
1, 2, 3, 4
};
List<string> keywordValues = new List<string>()
{
"Café", "Expensive", "Tasty"
};
var batchAppendKeywordValues = new BatchAppendKeywordValues
{
DocId = documentIds,
FieldName = "Keyword", //the name of the keyword fields
Keyword = keywordValues,
StoreDialogId = "storeDialogId",
ForceUpdate = false
};
//In this case if values of the fields match the existing ones, the batch append keyword and audit for it will be skipped
fileCabinet.PostToBatchUpdateRelationForBatchUpdateIndexFieldsResult(batchAppendKeywordValues);
batchAppendKeywordValues = new BatchAppendKeywordValues
{
BreakOnError = false,
DocId = documentIds,
FieldName = "Keyword", //the name of the keyword fields
Keyword = keywordValues,
StoreDialogId = "storeDialogID",
ForceUpdate = true
};
//In this case if values of the fields match the existing ones, the batch append keyword and audit for it will happen
fileCabinet.PostToBatchUpdateRelationForBatchUpdateIndexFieldsResult(batchAppendKeywordValues);
}
}
}