<h2>PaperCut Print Script of the Month</h2>
&nbsp;

With <a href="https://twitter.com/hashtag/pgm2016?src=hash" target="_blank" rel="noopener">PGM</a> out of the way, it is time to look at our monthly PaperCut Print Script again. This month it is time to recreate a feature that PaperCut already has, but with the added bonus of being able to change more. So, grab your favourite hot drink (coffee is the best option here) and we can get started.

&nbsp;

&nbsp;
<h4 style="text-align: left;">How to create a script to email users with a low balance</h4>
This feature is a way to email users when their balances get below a certain value. This script does assume you have two things in place already:

1. The mail server for notifications.

2. The email address for the users already synced from your sync source.

Let us get started... First create three variables these will be used for the email subject, email body (yes it supports HTML) and the value we want to check against.
<pre class="">var LOW = 1;
var SUBJECT = "Your balance is low";
var BODY = "Your PaperCut balance is getting low, Don't forget to top up soon or you won't be able to print";</pre>
&nbsp;

Once that is done we can add in the method to send an email which can be used to email one address or multiple by putting them in an array. We are just using the users email address which we can get from inputs.user.email which makes this easier.
<pre class="">actions.Utils.sendEmail(inputs.user.email, SUBJECT, BODY);</pre>
&nbsp;

All that is left to do now is wrap the sendEmail method in an <a href="http://www.w3schools.com/js/js_if_else.asp" target="_blank" rel="noopener">if statement</a> to check if the user's balance minus the cost of the job is less than or equal to the value you want to use as your minimum.
<pre class="">if (inputs.user.balance - inputs.job.cose &lt;= LOW) {
 // Send Email Here
}</pre>
&nbsp;

If you wanted to you could even do a check on the users group and only have it available for a certain group of users.

&nbsp;
<h3 style="line-height: 1.5em;">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 <a href="mailto:sales@selectec.com">sales@selectec.com</a></h3>
&nbsp;
<pre class="">/*
 * Email user when balance is low
 *
 * Read more at https://staging.selectec.com/script-of-the-month-5-low-balance-alert/
 */

function printJobHook(inputs, actions) {

  var LOW = 1;
  var SUBJECT = "Your balance is low";
  var BODY = "Your PaperCut Balance is getting low, Don't forget to top up soon or you won't be able to print";

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

  if ( inputs.user.balance - inputs.job.cost &lt;= LOW ) {
    actions.utils.sendEmail(inputs.user.email, SUBJECT, BODY);
  }
}
</pre>