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

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!

Thanks Chris. Where exactly i need to add ths script. I have tried but no success. Thanks.

It should replace the 7th line in the sample you posted above. If that's not working, could you provide some more information about what's going wrong? Thanks!

Hi Chris,

Thanks a lot, its working pretty well btw sorry for the late reply. Just tested and got the expected results. One more thing, can you please tell me how can i validate a date keyword (which is already set as mandatory) which should not be greater than the current date. I have tried but getting some exception. Any help on this will be appreciated. Thanks in adv.