cancel
Showing results for 
Search instead for 
Did you mean: 

Add a count down timer to a form

David_Chatterto
Star Collaborator
Star Collaborator

Hi,

 

I have a long questionnaire type Unity form and I have the session timeout to 60 minutes. I'd like to create a count down timer on the form so the user can see how much time they've got left. I've tried a few times but I can't seem to get it working, is this possible?

 

I'm using EP4.

 

Thanks.

1 ACCEPTED ANSWER

Mike_Walkuski
Employee
Employee

Hi @David Chatterton 

 

Here is a working solution that I whipped up really quick that should achieve what you are looking for.

 

The gist of it is,

I set a start time when the form is new and loaded. I then have a "Time Left" Field and a "Hidden Time Left" Field.

I then have a Custom Action that sets the two "Time Left" Fields to each other and then execute a Unity Script that performs the DateTime calculation and updates the Time Left field.

This update from the script then triggers the Custom Action to execute again since the two Time Left fields no longer equal each other and repeats the process.

I use Thread.Sleep in the script to ensure I am not running the script too often.

I have it set to two seconds in this example and am showing seconds instead of minutes to actually demonstrate the behavior easily, but this would work for Minutes too.

 

Example on the form: (These can be hidden as needed)

0c8bc3ea63a94f1ab0d64c918ae68d15

 

 

Custom Action to set "Start Time" and "Hidden Time Left" to kick off the second Custom Action

eaa98a50d721473286ec8255127952a9

 

Custom Action to set the "Time Left" Fields to equal each other and execute the Unity Script.

163fa57692ee454f9f3271c273226a9a

 

Unity Script to perform the calculation and set the "Time Left" field, which in turn will re-trigger the above Custom Action and repeat the process.

e1814f1d8fc5400cb02e057c657a196d

//Wait some time before calculatingThread.Sleep(2000);		//Get the Unity Form Field start timeHyland.Unity.UnityForm.ValueField starttimefield = args.FormInstance.AllFields.ValueFields.Find("starttime");app.Diagnostics.Write(starttimefield.DateTimeValue.ToString());//Add 60 minutes to the start timeDateTime calctimeleft =  starttimefield.DateTimeValue.AddMinutes(60);app.Diagnostics.Write(calctimeleft.ToString());			//Calculate time leftTimeSpan timespan = calctimeleft-DateTime.Now;			//Apply time left to Unity FormHyland.Unity.UnityForm.FormModifier formmodifier = args.FormInstance.CreateUnityFormModifier();app.Diagnostics.Write(timespan.TotalSeconds.ToString());formmodifier.SetFieldValue("timeleft",Convert.ToInt32(timespan.TotalSeconds).ToString());formmodifier.ApplyChanges();

 

Now this is triggering the client to reach out to the Web/AppServer as that is where the Unity Script is executed so I would ensure to test it to make sure it meets you needs and doesn't cause any undesired behavior, but it should be a good starting point for you.

 

I hope this helps! Good Luck!

View answer in original post

6 REPLIES 6

 

@Mike Walkuski 

Question, how hard would this be to adapt to WorkView but with a twist.  Have the same START TIME but setup a unity script to cellulate the amount of time and add to an attribute based on a populated END TIME.

I know there are expressions that can be run to which are usually based on movement, but I was thinking more along the lines of...
1 - Putting the Object in their Start Queue and populate the START TIME ( Object is a compliance object they need to complete and correctly in a specific amount of time )
2 - Once the form moves to one of 4 status levels in the WorkView Class populate the END TIME
3 - Display on the Object in their "time to complete" based on the two values.
4 - Based on their time to complete we could then let me "Do Over" or accept their time to complete?

Dean

I am curious if the WV View Iframe control would allow you to implement a true web-based timer.