West Face University has a student population of 10,000 full-time students and over 1,000 staff. Currently their costing model has a charge of $0.50 for A3 and $0.40 for A4 pages. They would, however, like more control over the cost structure by setting a different price for staff and students. They would like to charge staff $0.30 for A3 and $0.15 for A4 pages.
They would also like to encourage students to do their copying during off-peak periods to decrease the queues at the MFDs. West Face University are willing to offer a 10% discount for copy jobs performed before 11 a.m. and after 3 p.m..
Solution description
Using device scripting, the West Face University will:
-
apply a different cost model for staff and students
-
offer a discount for any job performed between 3 p.m. and 11 a.m..
Implementation
This example demonstrates how to create a device script from scratch, without the use of a recipe or snippet.
To create this script, you will:
For more information about creating device scripts, see:
- Device scripting overview
- Creating device scripts
- Device script API reference
- Tips for device scripting
- Troubleshooting device scripts
Add a ‘deviceJobLogHook’
Every script needs to start with a “hook”. This hook defines the event that triggers the script to run. In this example, the script needs to be triggered when a user performs a copy job, so deviceJobLogHook
is the right hook.
-
Click the Devices tab.
The External Device List page is displayed. -
Select a test device.
The Device Details page is displayed. -
Click the Scripting tab.
-
Select the Enable device script checkbox.
By default, thedeviceLoginHook
is included in the script editor.In this example, you want to use
deviceJobLogHook
. This function needs to do the following:-
Check if it is NOT a copy job, and if it is not, don’t run the script (see 1 in the image below).
-
Check if the user is a staff member and if so, call the
adjustCopyCostForStaff
function, which calculates the copy job cost (see 2 in the image below). This function is defined later in the script. -
Check if the user is a student and has performed the copy job during the off-peak period and if so, call the
adjustCopyCostForOffPeak
function, which calculates the copy job cost (see 3 in the image below). This function is defined later in the script.
-
-
In the function name, change
deviceLoginHook
todeviceJobLogHook
. -
Below the function name, add an
if
statement to check if the job is a copy job.// If it's not a copy job we won't run the rest of this script. if (!inputs.job.isCopy) { return; }
-
Add an
if
statement to check if the user is a staff member and if so, calculate the copy job cost. This statement calls the function (adjustCopyCostForStaff
) that you will define in Create a function to adjust the cost for staff .// staff get charged under a different cost model if (inputs.user.isInGroup("Staff")) { adjustCopyCostForStaff(inputs,actions); }
-
Add an
if
statement to check if the user is a student and has performed the copy job during the off-peak period and if so, calculate the copy job cost. This statement calls the function (adjustCopyCostForOffPeak
) that you will define in Create a function to adjust the copy pricing in off-peak periods .// students can get charged extra for using the copier // during peak hour. if(inputs.user.isInGroup("Students")) { adjustCopyCostForOffPeak(inputs,actions); }
Create a function to adjust the cost for staff
Next, you need to create a function that calculates the copy cost for staff. This function is called from the deviceJobLogHook
and includes:
-
a variable that defines the staff cost model (see 1 in the image below)
-
variables used to determine the page size and number of pages in the copy job (see 2 in the image below)
-
variables used to calculate the adjusted job cost (see 3 in the image below)
-
applies the adjusted job cost (see 4 in the image below).
-
Add the function:
/** * This function adjusts the job cost if it's a staff member. */ function adjustCopyCostForStaff(inputs, actions) { }
-
Before the closing parenthesis, add a variable that defines the staff cost model. These variables will be referenced when the cost is calculated.
// Using a customised pricing model here // We'll keep it simple and differentiate only by paper size - // we won't worry about duplex or color mode for this example. var staffSimpleModel = { A3: 0.3, A4: 0.15, Default: 0.15 // fall back to default if we can't find the right size };
-
Add the variables used to determine the page size and number of pages in the copy job:
// analyze the job var totalPages = inputs.job.totalPages; var paperSizeName = inputs.job.paperSizeName;
-
Add the variables used to calculate the adjusted job cost based:
// do a simple calculation var costPerPage = staffSimpleModel\[paperSizeName\] ? staffSimpleModel\[paperSizeName\] : staffSimpleModel\["Default"\]; var adjustedCost = costPerPage \* totalPages;
-
Add the
actions
to apply the adjusted job cost and add a comment to the Job Log.// change the job cost actions.job.setCost(adjustedCost); actions.job.addComment("Costs adjusted for staff member");
Create a function to adjust the copy pricing in off-peak periods
Next, you need to create a function that calculates the copy cost for staff. This function is called from the deviceJobLogHook
and:
-
includes variables that define the peak period and discounted rate for off-peak (see 1 in the image below)
-
includes variables used to determine if the coy job has been performed in the peak period (see 2 in the image below)
-
determines if the job has been performed in the off-peak period and if it is, applies the adjusted job cost (see 3 in the image below).
-
Add the function:
/** * For this function we'll adjust the copy job pricing * if the job was done during peak hours. */ function adjustCopyCostForOffPeak(inputs, actions) { }
-
Before the closing parenthesis, variables that define the peak period and discounted rate for off-peak.
var PEAK\_PERIOD\_START = 11; // 11am var PEAK\_PERIOD\_END = 15; // 3pm var DISCOUNTED\_RATE = 10; // 10% discount for off peak };
-
Add the variables used to determine if the copy job has been performed in the peak period. These variables will be referenced when the cost is calculated.
var cost = inputs.job.cost; var date = new Date(); var hour = date.getHours(); };
-
Add the actions to determine if the job has been performed in the off-peak period and if it is, applies the adjusted job cost:
if (hour < PEAK\_PERIOD\_START || hour >= PEAK\_PERIOD\_END){ var discountedCost = cost - (cost \* (DISCOUNTED\_RATE / 100)); actions.job.setCost(discountedCost); actions.job.addComment("Discount applied for copying during off peak"); }
-
Click Apply. You have now created the script.
Test your script and go live
Before you copy your script to production devices, make sure you check that it works in on a test device.
-
Check the following on a test device:
-
As a student, perform a copy job after 3pm and check if the user account was charged the discounted cost.
-
As a student, perform a copy job between 11am and 3pm and check if the user account was charged the standard cost.
-
As a staff member, perform a copy job and check if the user account was charged the cheaper cost.
-
-
Copy your device script to the required devices.
Comments