09-04-2014 08:32 AM
We have a program developed using Unity Java API to update keywords (StandAlone type) in Onbase. Our code was working as expected until sometime last week. Starting day before yesterday whenever we try to update keywords using Unity API, all the keywords on the document expect but the keyword we are trying to update are getting deleted automatically. Below is the sample code I am using to update keywords. FYI, I have already reached out our local Onbase admins to see if there’s something changed on the server recently that might causing this issue. I was just wondering if ya'll have any thoughts on this.
DocumentLock docLock = document.LockDocument();
if(docLock.getStatus() == DocumentLockStatus.LockObtained){
KeywordModifier keyModifier = document.CreateKeywordModifier();
// Find Keyword Type
KeywordType keywordType = appCore.getKeywordTypes().Find("Company");
//Find KeywordRecord Type
KeywordRecord keywordRecord = document.getKeywordRecords().Find(keywordType);
// Create Keyword Object
Keyword newKeyword = keywordType.CreateKeyword("4950");
for(Keyword keyword : keywordRecord.getKeywords()){
keyModifier.UpdateKeyword(keyword, newKeyword);
}
//Apply Changes.
keyModifier.ApplyChanges();
}
docLock.Release();
Thanks,
Harish
09-04-2014 11:29 AM
Hello Harish,
From the way I am understanding your example code, I am not surprised that keywords are being "deleted" from the Document. That is exactly what this code does in most circumstances. I am not sure how this functioned properly previously (the code will work as you expect in a very narrow set of conditions), but I would suggest that you review what Documents this code has touched to ensure that the Keywords are as you expect them to be.
Here is what your code is essentially doing:
The code does not "delete" Keywords in the strict sense of the word; it updates them all to the same value. OnBase then condenses all of these instances of the same Keyword value into a single Keyword, effectively "deleting" all of the existing values besides the one you created.
What you should do is, within the for loop over all of the Keywords, check if the Keyword is of the KeywordType you are looking for and update the value only if the Types match. This way you only update all of the Keywords of one KeywordType instead of all the Keywords on the Document.
09-04-2014 12:02 PM
Thanks for your response Brian.
I should have been more clear on the Keyword update issue. The issue there is, like, let’s say we have DocumentType ‘Resume’ and we have Stand Alone keywords Company, Department and UserID setup for the DocumentType ‘Resume’. In the code, when I try to update Company keyword, the Company keyword is getting updated as expected, but it is deleting Department and UserID keywords/keyword value(s).
Makes sense?
Thanks,
Harish
09-04-2014 12:16 PM
Hello Brian,
Sorry, I was reading you response once again. I think you it was clear to you what the issue was.
From the highlighted code below, doesn’t it only bring back the KeywordTypes I am looking to update because I have the following two lines in my code as well?
// Find Keyword Type
KeywordType keywordType = appCore.getKeywordTypes().Find("Company");
//Find KeywordRecord Type
KeywordRecord keywordRecord = document.getKeywordRecords().Find(keywordType);
for(Keyword keyword : keywordRecord.getKeywords()){
keyModifier.UpdateKeyword(keyword, newKeyword);
}
Thanks,
Harish
09-04-2014 01:35 PM
The call to document.getKeywordRecords().Find(keywordType) will return the standalone KeywordRecord instance for the Document. This KeywordRecord will contain every standalone Keyword associated with the Document, not just the single KeywordType you specify in the Find() call.
Your code looks vaguely similar to one of the examples in the OnBase SDK. However, you are missing a single method call that makes all of the difference:
// Retrieve keyword to update (could be multiple instances of the keyword)foreach (Keyword keyword in keyRecord.Keywords.FindAll(keywordType)){ // Update the keyword in the keyword modifier object keyModifier.UpdateKeyword(keyword, newKeyword);}
Notice the second call to FindAll(KeywordType) from the Keywords property that will return all instances of the KeywordType in the KeywordRecord.
If you do not want to put that second call to FindAll() (because the method does the same thing by running through the list internally), you can implement the conditional I previously suggested within the body of the for loop. Both should be functionally equivalent for your use case.
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.