07-31-2019 08:11 AM
I am adding new keywords via a ReindexProperties.AddKeyword object, this adds the keyword but the value of the keyword is not added.
I am doing it via this:
ReindexProperties.AddKeyword(keyword); //Where keyword is of type Hyland.Unity.Keyword
08-01-2019 05:36 AM
Below is a tested code example that I have confirmed. Please feel free to follow this design and let me know how it works for you. In my case, I put this into a system task for testing. It will also work as-is in a workflow action if that is more relevant for you.
public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
{
try
{
Document theDoc = args.Document;
DocumentType newDocType = app.Core.DocumentTypes.Find("the new doc type name");
if (newDocType == null)
{
throw new Exception("New Document Type not found.");
}
Storage storage = app.Core.Storage;
ReindexProperties reindexProps = storage.CreateReindexProperties(theDoc, newDocType);
if (reindexProps == null)
{
throw new Exception("ReindexProperties not created.");
}
KeywordType newKeywordType = app.Core.KeywordTypes.Find("your new keyword type name");
if (newKeywordType == null)
{
throw new Exception("New Keyword Type not found.");
}
Keyword newKeyword = newKeywordType.CreateKeyword("Smith");
if (newKeyword == null)
{
throw new Exception("New Keyword not created.");
}
reindexProps.AddKeyword(newKeyword);
Document newDoc = storage.ReindexDocument(reindexProps);
app.Diagnostics.Write("Document Successfully ReIndexed, Document ID = {0}.", newDoc.ID);
args.ScriptResult = true;
}
catch (Exception ex)
{
app.Diagnostics.Write("ERROR: {0}", ex);
args.ScriptResult = false;
}
}
Cheers!
07-31-2019 11:06 AM
Something to try:
Instead of attempting to add the new keyword during the Reindex process, can you add it to the Document after it's been Re-Indexed? I.E. leave that Keyword off the Properties, call ReindexDocument, then create a Document KeywordModifier, AddKeyword, ApplyChanges -- same error?
07-31-2019 11:40 AM
I'll give that a try Adam.
08-01-2019 06:27 AM
I tried just calling ReindexDocument() before trying to add the new keyword via the KeywordModifier object and get the object reference exception on call to ReindexDocument without even trying to add or remove keywords.
08-01-2019 06:31 AM
Do you happen to know if there are any hidden or readonly keywords configured on either DocType, or any keywords that have been marked as required to be present?
08-01-2019 06:38 AM
The two document types I've been using for testing neither have read-only or hidden keywords, and the document does get re-indexed to the new document type, but it still throws the exception instead of returning the new document. Which is really weird. Maybe there is a problem in the Rendition /Revision Control Settings for the document types in the configuration? Do you happen to know if there are any specific settings necessary in config for this action to work correctly in Unity?
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.