cancel
Showing results for 
Search instead for 
Did you mean: 

Unity Script to Compare 2 Standalone Keywords and Delete 2nd Keyword If Match Is Found

Anthony_Mada
Champ on-the-rise
Champ on-the-rise

Hello Everyone,

I am a longtime OnBase admin and fairly new to the Unity API.  I have a document that has 2 keywords, AssignedTo and ApprovedBy.  These documents are in a rules-based queue and use the AssignedTo keyword to assign documents to different users.  A document can be assigned to multiple approvers (at the same time) and will reside in the queue until all approvers have applied their approval using the ApprovedBy keyword. 

I tried to do this in workflow using properties, but it's not working, so I tried to create a unity script that will check the ApprovedBy keyword and if a match is found delete the matching AssignedTo keyword.  Here is what I have so far.  Any help you can provide would be greatly appreciated.  Thank you for reading my post.

 

 

 

 

2 REPLIES 2

Aki_Daiguji
Star Contributor
Star Contributor

Hi Anthony,

I believe the reason why your code is not working is because you are trying to compare between the ApprovedBy Keyword object and the AssignedTo Keyword object. These two Keyword objects will never be the same since they are different Keyword Types, even though the value may be the same. What you want to do is compare the values of these Keywords.

However, with your current code, it's possible that you may end up making multiple Keyword removals on a single document. If you happened to have 3 matching values, that means you'll be calling the KeywordModifier.ApplyChanges method 3 times, which become 3 separate calls to the AppServer.

What I would suggest, is to create 3 individual generic list objects (since the values are all going to be a string, all 3 can be a list of string). First 2 list will contain the list of values from the ApprovedBy Keyword and AssignedTo Keyword. The 3rd list will contain the matching value that you will get from comparing the first 2 lists.

After you verify that the 3rd list is not empty, loop through and call the RemoveKeyword method for however many items there are in the 3rd list. After the loop, call the KeywordModifier.ApplyChanges method once, so all the keyword removals you need to apply will only happen once.

EDIT: Now that I look at it, you could do this without having the list objects. You can use the same loop you have, chang the comparison so that it compares the value of the Keyword, and in the loop, call the RemoveKeyword method. You'll also want to set a boolean variable to see if a RemovalKeyword method was called. Then outside of the loop, check the boolean variable, and call the ApplyChanges method.

Hi Aki,

Thanks for helping me work through my issue!  I was able to get my code to work by comparing the values of the keywords.