cancel
Showing results for 
Search instead for 
Did you mean: 

Unity Script to generate Autofill with "Date & Time"

Jed_Kaplowitz
Star Contributor
Star Contributor

I have this weird problem (at least I think it's weird).

I am trying to insert a "Date & Time" into an Autofill using a Unity Script.
The DateTime object is valid and I even do a "ToString()" on the object and display it in the Diagnostics Console.
The object doesn't fill the keyword when I use it in an "Upload Document" and try to autofill.

I try a string with a DateTime.TryParse and that works.
Then I try to convert the original DateTime to a string and back to a DateTime and that doesn't work.

The string is EXACTLY the same as the DateTime Object ToString()

Below is my code:

public void SetKeywordType (Hyland.Unity.Application app, string name, ExternalAutofillKeysetData data, Hyland.Unity.ExternalAutofillKeysetEventArgs args, DateTime datavalue)
{
     try
     {
          KeywordType descType = args.KeywordTypes.Find(name);
          DateTime newDT;
          string strDT = datavalue.ToString ("MM/dd/yyyy hh:mm:sstt"); // << this doesn't work
          //string strDT = "07/07/2015 03:15:56PM"; // << this works
          app.Diagnostics.WriteIf (Diagnostics.DiagnosticsLevel.Verbose, "STR DATETIME : " + strDT);

          bool success = DateTime.TryParse (strDT, out newDT);
          if (success == true)
          {
               app.Diagnostics.WriteIf (Diagnostics.DiagnosticsLevel.Verbose, "NEW DATETIME : " + newDT.ToString());
               Hyland.Unity.Keyword kw = descType.CreateKeyword(newDT);
               app.Diagnostics.WriteIf (Diagnostics.DiagnosticsLevel.Verbose, "kwName = " + kw.KeywordType.Name + " " + kw.DateTimeValue.ToString());
     
               if (kw != null)
               {
                    data.SetKeyword( kw );
               }
               else
                    app.Diagnostics.WriteIf (Diagnostics.DiagnosticsLevel.Verbose, "Keyword: " + datavalue + " IS NULL");
          }
          else
               app.Diagnostics.WriteIf (Diagnostics.DiagnosticsLevel.Verbose, "ERROR: Could not Parse Date");

     }     
     catch( Exception ex )
     {
          app.Diagnostics.Write( ex );
     }
}

1 ACCEPTED ANSWER

Jed_Kaplowitz
Star Contributor
Star Contributor

if you read my previous comments you will see that I have been testing my results in both the OnBase Thick Client and the testing area of the AFKS dialog box (OnBase Config) and this was working in neither.
One of my coworkers said: "Does it work in the Unity Client?", so I tried it and it worked!
Every date and time worked in the Unity Client.
With that I called Hyland support because this is now beyond an API question.

Hyland says: ". We do parse date values differently in Unity vs. Thick Client. Unity is able to parse DateTime values, while Thick Client just parses Date values."

Argh!
Mystery solved.

Thanks,

Jed K

 

View answer in original post

9 REPLIES 9

Patrick_Ramser
Star Contributor
Star Contributor
Hey Jed,

Just to be completely detailed with this, is your diagnostic data pointing to the DateTime.TryParse, the CreateKeyword method using the DateTime, or the CreateKeyword using the string from the parsed value?

It sounded like the CreateKeyword using DateTime, but I wanted to be sure.

I tried the DateTime.TryParse by pushing a date through and back as a string and back; everything seemed cool. No loss of information or changes locally. The CreateKeyword with the DateTime is interesting since we need to serialize that date before we send it across the wire.

Just for complete transparency's sake, could you provide a stack trace from the particular error you're getting, Jed? If it's too much of a pain, let me know, but it would help miles to see the part of the API that's choking on the date value or the string of that.

Jed_Kaplowitz
Star Contributor
Star Contributor
Thanks for the reply.
I've tried a bunch of things and I now see that just changing the time works.
I hardwire a time into the DateTime TryParse object and it fails.
I hardwire a different time (same date) and it succeeds.
5/7/2015 5:54:04 PM fails.
5/7/2015 11:54:04PM succeeds.
The DateTime object is valid. I test it in the diagnostic console.

I am using a DateTime but I will try a string representation of the DateTime object.
Stack Trace...
There is no error. The keyword field is just blank after the autofill.

Jed_Kaplowitz
Star Contributor
Star Contributor
This didn't work either:
string strDT = datavalue.ToString ("MM/dd/yyyy hh:mm:sstt");
Hyland.Unity.Keyword kw = descType.CreateKeyword(strDT);

Patrick_Ramser
Star Contributor
Star Contributor
Hey Jed,

Which client are you attempting this in? Is it the Thick, Web, or Unity Client? And if you have multiple available, do you get different results in one vs. another?

Also, this isn't a must; I'm just interested; but, does the format of the date you see in the client for the keyword match that of the format you're inserting the keyword with?
Getting started

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.