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 09:59 AM
Correct.
07-31-2019 10:42 AM
When you create the ReindexProperties object, the "yourDocType" in your code should be different than the document's current document type. I don't believe you can ReIndex a document to the same document type. Can you add a little more to your scenario/story to help give better advice?
Best Regards!
07-31-2019 10:48 AM
Updated Comment:
When you create the ReindexProperties object, the "yourDocType" in your code should be different than the document's current document type. You can't ReIndex a document to the same document type. Can you add a little more to your scenario/story to help us provide better advice?
Best Regards!
07-31-2019 10:50 AM
I'm not re-indexing to the same documentType, I pass the current document and the new document type when creating the ReindexProperties, this all works fine, it's when adding a new keyword which does not exist on the old document type it adds the keyword but doesn't fill in the value when re-indexing and throws the above exception on the call to ReindexDocument(). The document gets moved to the new document type as expected even with the exception message but the new keyword is not populated with it's value. And I've read the entire SDK article you linked to, it doesn't give any kind of coding example so I am doing the best I can with this. I have no idea why it isn't working correctly.
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!
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.