What is Scripting? - A Basic Introduction - TWP

This article will show some examples of different ways that the scripting language can be used. But first, a brief explanation about scripting. Scripts are like mini programs that run on each line of the time card, one by one, and make changes based on various conditions defined in the script. The basic structure of a script is to check a condition (Does this punch set meet a set of criteria?) and if yes, then execute a command that alters the time card in some manner.

Where do I enter scripts?

Scripts are entered through various types of Script Processing rules. They can all be found on the Processing Rules page under three different categories of rules:
  • Scripting
  • Accruals
  • Overtime
Most of the script rules are found in the Scripting category. A more detailed explanation of the different Script rules can be found in the article Script Boxes.

Once a script has been typed into the rule's text box, you would click "Save" in order for the script to start running on the time card.

How do I create scripts?

You can type a script directly into the Script rule text box, but we suggest using a simple text editor like Notepad for creating and saving your scripts. Do not use Microsoft Word. There are some issues related to how Word formats quotation marks that will cause errors with your scripts.

More on the best practices of scripting can be found in Best Practices.

Are scripts reversible?

Scripts only change the way the original data is displayed or exported. It does not make any permanent changes to the original data. If you do not like what your script is doing you can always take it out and it will revert back to the original punch data.

Also, in TimeWorksPlus, scripts do not run on Finalized pay periods. So if a pay period has been Finalized, the script will not change any of the time card until you un-finalize the pay period.

What can a script do?

Below are some examples of basic scripts that might help you understand, on a elementary level, what a script can do.

Using the hours Value

The keyword hours returns a decimal value of hours for a punch set. So for each line on a time card, you can use hours in your script to find out how long the employee worked between IN and OUT. Once this value is known you can use the following relational operators to make changes based on that value.

Below is an example of this script that changes the pay rate if the employee works more than 8 hours. 

if (hours > 8){
    payrate = payrate * 1.5;
}


Other operators can be used as well (without the quotes): 
  • Less than: '<'
  • More than: '>'
  • Equals: '='
  • Does not equal to: '<>'
  • More than or equals to: '>='
  • Less than or equals to: '<='

You can also make a punch set default to an hour increment and overwrite the actual hours based on the in and out. Below is an example of this:

if (employee.department = "100"){
     hours = 3;
}


In the above it reads if they have 100 in the Department field of Employee Setup then make all punches, regardless of an in or out punch, an amount of 3 hours.

Using Clock Prompts

The following example is based on a Labor prompt (like the "X" Prompt) called "Job. In this case, the "Job" prompt has the options 1, 2 and 3 set. When the employee enters any of those numbers at the prompt, it will replace the number with the name of the corresponding choice accordingly.

if (Job = "1"){ 
  Job = "Server"; 
}
if(Job = "2"){ 
  Job = "Hostess"; 
}
if(Job = "3"){ 
  Job = "Bartender"; 

Changing Categories

A script can also be written to change a punch category based on certain criteria. For instance, this script uses the touches function to determine if a punch set crosses into a specific time window. If it does, then the punch category is change from Regular to D1 or D2.

if(touches (5:30pm, 10:00pm)){
   category = "D1";
}
if(touches (10:30pm, 4:30am)){
    category = "D2";
}

Pay Rates

This example alters not only the category for hours worked on a Saturday and Sunday, but it also adds $1.25 to the pay rate.

if("SU" contains weekday (punchdate)) {
   category = "WKND1";
   payrate = payrate + 1.25;
}

Using Intime / Outtime

This example changes the category to a specific shift category based on the In Punch. In this example, all employees working the 2nd Shift clock in between 2pm and 3pm.

if((intime > 2:00pm) and (intime < 3:00pm)){
   category = "2nd Shift";
}


The same type of script could be used based on the outtime. Here, employees that clock out between 7am and 8am are working the 3rd Shift.

if((outtime > 7:00am) and (outtime < 8:00am)) {
    category = "3rd Shift";
}

Changing Overtime Threshold

Scripting can also be used to change certain employees overtime thresholds based on a Department or Location. In this script, employees that work at Location 100 have a daily overtime threshold of 8 hours.

if(employee.location = "100"){
   ot1daythreshold= 8;
}


 

Did you find this article helpful?