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

I added two screenshots, from the config, it doesn't appear to me that any of the keywords are hidden or read only, the one document type doesnt require any of the keywords, the other one does require 4 of the 5 keywords, but as stated the reindex succeeds even though it throws an exception but the keyword year is not populated on the one which contains 4 requireds. It just shows in Onbase as a blank value, even though the keyword which is created is the correct datatype and has a value when passed into the .AddKeyword method. Our company is using OnBase 17, just in case this is a version issue.

I went through the configuration tool and found the only difference in documents is the autofill keyword set drop down setting. Is that something that can affect re-indexing?

I gave up on trying to find why some document types will re-index properly with the call to ReindexDocument and others throw an exception, I am just catching the exception and checking for the specific exception type, and if I get that exception type I use a KeywordModifier to update existing keywords and add new ones. Not ideal but it works.

Hey Ryan --

Thanks for letting us know -- I was unsuccessful in getting this replicated in my system, so I'm glad you found a workaround that works for you. I'll continue to look into this in the meantime and post here if I find anything else out.

Matt_Wallace
Champ in-the-making
Champ in-the-making

How are you getting the initial ReindexProperties object?  Like this?

ReindexProperties reindexProps = Application.Storage.CreateReindexProperties(yourDoc, yourDocType);