You are viewing limited content. For full access, please sign in.

Question

Question

How do I format fields to add total hours in a time sheet form?

asked on March 23, 2020

I am trying to create a timesheet for my department but I am having some issues adding the fields to find the total hours worked.  Do I need to format the fields to match a time format like in excel?  What would be the formula?

0 0

Replies

replied on March 26, 2020 Show version history

Armando,

I would like to suggest build a Workflow Service Task within your business process.  Workflow will allow you to use a Script Activity to handle the time calculation.  Take a look at this post in answers.  Note: I have tried a few methods using Date Token Calculator however it is not well suited for this application.

This example uses two simple forms (identical except for names/labels):

1) Clock In Form 

2) Clock Out Form

Your application may be different however I have attached screenshots of a process and workflow that correctly calculated a time span using a script. 

This process runs when started and presents the Clock IN form.  Once a user "clocks in" then the process begins a user task to "clock out" but must wait for the user to actually perform the action.  Once clocked out, the workflow service task can calculate the time difference.

The workflow retrieves the business process variables, especially the two variables noted.  These values are of type DateTime therefore subtracting DateTime variables it makes sense to use TimeSpan type for the result.  The link at beginning of this post uses Integer.  Choose the correct value for your actual application.

1) Retrievetimechange__Start Date --> used as CLOCK IN time

2) Retrievetimechange__Submission Date --> used as CLOCK OUT time

 

My test script code:

When you use a Script Activity there will be skeleton VB Script code.  Insert your code directly below the lines that reads  "   'Write your code here.  " but above the "End Sub" within Sub Execute().  

Dim ttimespan as TimeSpan

Dim starttime as DateTime = gettokenvalue("Retrievetimechange__Start Date")

Dim stoptime as datetime = gettokenvalue("Retrievetimechange__Submission Date")

 

** Please note I retyped this instead of copy and paste so I hope there are no typographical errors

 

Using the simple example presented here I was able to clock in, clock out, and observe my time span calculated as a token.  From this point on your actual application will be different but this should provide a very nice step in the right direction.

 

Kind regards,

Justin Warner

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.