cancel
Showing results for 
Search instead for 
Did you mean: 

Unity API - Programatically Validate Keywords before the Document Upload in Unity

Mahesh_L
Star Contributor
Star Contributor

Hi All,

I am trying to validate few of the keyword types which are already configured for a document type. I have started with validating a keyword with empty check.

But the script is not working as expected. The script is getting triggered while clicking the "Upload" button in Unity but the expected result is not arrived. Dont know what i am doing wrong. Please help me. Below is the script.

FileImportKeywordPanel keywordPanel = args.KeywordPanel;
KeywordType keywordType = app.Core.KeywordTypes.Find("Serial Number");
if(keywordType == null)
{
throw new Exception("Could not find serial number keyword type");
}
KeywordRecord keywordRecord = keywordPanel.KeywordRecords.Find(keywordType);
if(keywordRecord == null)
{
throw new Exception("Could not find serial number keyword type in keyword record");
}
try
{
Keyword keyword = keywordRecord.Keywords.Find(keywordType);
if ((keyword == null) || (keyword.IsBlank))
{
MessageBox.Show("Please fill the Serial Number", "Validation", buttons);
args.ScriptResult = DocumentFileImportPreArchiveScriptResult.Cancel;
return;
}
}
catch(UnityAPIException unityEx)
{
app.Diagnostics.Write(unityEx.ToString());
}

With Regards

LMK

1 ACCEPTED ANSWER

Chris_Tucker
Star Contributor
Star Contributor

Hi LMK,

keywordPanel.KeywordRecords.Find(keywordType) isn't returning a keyword record because the keyword is blank. To get the functionality that you want, you can use: keywordPanel.KeywordRecords.Find(kr => kr.KeywordRecordType.KeywordTypes.Contains(keywordType)).

This behavior is due to the way that blank standalone keywords are handled. When the keyword is blank, it is not present in the keyword record. Only keywords with values are included in the standalone keyword record. Find(keywordType) looks for a keyword record which contains a keyword of the type in it. Since the keyword is blank, it does not find any keyword records. Using the keyword record type lets you find a keyword record which is configured to contain a keyword type, regardless of whether that keyword is currently present in the keyword record or not.

Hope this helps!

View answer in original post

7 REPLIES 7

You can check if a date keyword has a value after the current date by using: DateTime.Compare(keyword.DateTimeValue, DateTime.Now) > 0. The DateTimeValue property will throw an exception if the keyword is blank or if it's not configured as a Date or DateTime keyword, so make sure that you check that before performing the comparison.

Thanks Chris. I could able to achieve what i wanted. Thanks a lot for your timely help. This is working fine in OnBase15 not in OnBase13. Is this expected behaviour?.

The File Import - Pre Archive script was added in OnBase 14, so it won't work in versions prior to that. If you need this functionality in OnBase 13, your best bets would probably be to write a VBScript (which only execute in the thick client), route the documents through a scan queue and use a Post Index script for validation, or use Workflow to perform the validation.
Hope this helps!