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

Ryan_Wilson2
Star Contributor
Star Contributor

Gives: An error occurred within the Unity API: Object reference not set to an instance of an object.

Ryan_Wilson2
Star Contributor
Star Contributor

It throws the exception on a call to this: .Core.Storage.ReindexDocument(reindexProperties);

Adam_Kuhn
Star Collaborator
Star Collaborator

How did you create keyword?

Application.Core.KeywordTypes.Find(keywordName).CreateKeyword(valueForKeyword);