cancel
Showing results for 
Search instead for 
Did you mean: 

ReindexProperties.AddKeyword adds the keyword but doesnt add the value

Ryan_Wilson2
Star Contributor
Star Contributor

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

1 ACCEPTED ANSWER

Shane_Cook1
Star Contributor
Star Contributor

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!

View answer in original post

27 REPLIES 27

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?

I'll give that a try Adam.

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.

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?

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?