img

PaperCut Print Script of the Month #10 – Confirm jobs with high cost


PaperCut Print Script of the month

This months script is a nice and easy one and something that we thought was included in the recipes that come with PaperCut but we couldn’t see it. The goal is to inform users of the jobs cost is over a certain amount and give them the option to carry on printing or cancel the job, Once you have found a hot cup of coffee we can get to work.

 

The script is almost the same as the “Confirm jobs with a high number of pages” recipe included but with the slight change of focusing on the cost instead of the pages. The first thing we will want to do is work out what our cost limit will be and to set the message to show to the user.

var COST = 1.0;
var MESSAGE = "This job costs over £" + COST + " are you sure you want to print it?";

Now we need to check to see if the print job costs more than the cost set above which we can do using the inputs.job.cost method.

if (inputs.job.cost >= COST) {
  // This will only run if the jobs cost is more than our limit
}

We know that we have the right jobs now so we can show the prompt to ask the user if they want to print making sure that we set the result to a variable, so we know when to cancel the job.

var response = actions.client.promptPrintCancel(MESSAGE);

The response variable will now contain one of 3 options PRINT, CANCEL and TIMEOUT. PRINT and CANCEL are based on the 2 buttons that appear and TIMEOUT will occur if nothing is selected at all. All we need to do from here is cancel the job if the response is either CANCEL or TIMEOUT if the user selects print we don’t want to do anything so we can just ignore it.

if (response == "CANCEL" || response == "TIMEOUT") {
  // cancel the job then exit the script
  actions.job.cancel();
  return;
}

That is it for this month and as always the complete PaperCut Print Script is below. If you have your own requirements for a print script and you don’t have the time or in-house experience to make it you can find out how we can help you by sending an email to our sales team at sales@selectec.com

/*
* Ask users to confirm the print job if over a certain cost
*
* Read more at http://selectec.com/script-of-the-month-10-confirm-jobs-high-cost/
*/
function printJobHook(inputs,actions) {
  // What is our limit for alerts?
  var COST = 1.0;
  // This is the message we will show the users
  var MESSAGE = "This job costs over £" + COST + " are you sure you want to print it?";

  if (!inputs.job.isAnalysisComplete) {
    return;
  }

  // Check the job cost
  if (inputs.job.cost >= COST) {
    // Show the prompt and set the response to the response variable
    var response = actions.client.promptPrintCancel(MESSAGE);
    // If user clicked Cancel or there was a timeout
    if (response == "CANCEL" || response == "TIMEOUT") {
      // Cancel the job and exit the script
      actions.job.cancel();
      return;
    }
    // User pressed print so we will let the job go
  }

}
PaperCut Print Script
Latest News from Jonathan Bennetts
img

PaperCut and Access Management

Access Management and Identity as a Service (IDaaS) solutions for PaperCut...

Written by: Jonathan Bennetts

More
img

PaperCut ends client support for 32-bit operating syst...

A long time ago, in a country far far away... PaperCut announced they were...

Written by: Jonathan Bennetts

More

img

We have worked with Selectec for over 5 years. With their support we have been able to satisfy our direct and indirect clients with an extremely quick turnaround time in the supply of software. Their customer service is outstanding. The personal touch they offer, their flexibility and quick reaction time, comforts us in knowing that if things were to go wrong, the support is always there.

John Sweeney, Head of Product & Solutions Support Group Toshiba UK
Back to Top ↑