<h2 style="text-align: left; line-height: 1.5em;">Welcome to the first PaperCut Print Script of the month</h2>
<h3 style="text-align: left; line-height: 1.5em;">As Halloween is approaching I have decided to take to the Selectec tradition of picking on <a href="/team/ross-malyon/">Ross</a> online. This month we will be creating a simple PaperCut print script which will cancel or double the cost of his print jobs depending on what second his job was sent. So, grab a cup of coffee and we can start when you're ready.</h3>
&nbsp;
<p style="text-align: left;">So, the first thing we are going to do is create two variables, one for the user we are going to target and another to hold the seconds from the time the job was sent. Creating a variable is nice and easy in Javascript we just come up with a name that we can remember or easily recognise later and assign it a value.</p>

<pre>var username = "Ross";</pre>
&nbsp;
<p style="text-align: left;">Our second variable is going to use the <em>inputs.job.date</em> method, and the <em>seconds</em> from the time the job was submitted.</p>

<pre>var seconds = inputs.job.date.getSeconds();</pre>
&nbsp;
<p style="text-align: left;">Now that we have the variables we need let's build out our <em>if</em> block. To make sure Ross has a hard time, we are only going to run the script if the job was submitted using his username using the inputs.job.username method. This could also be changed to a group of users by using inputs.user.isInGroup(group_name_variable).</p>

<pre>if ( inputs.job.username == username ) {
	// The rest of our code will go here
}</pre>
&nbsp;
<p style="text-align: left;">Now inside that <em>if</em> block we are going to add another if block to compare the second's value against 2 numbers so <em>if</em> <em>seconds</em> is 11 or <em>seconds</em> is 22 we are going to cancel the job and send a message back to him to tell him it has been cancelled.</p>

<pre>if ( seconds == 11 || seconds == 22 ) {
	actions.job.cancel();
	actions.client.sendMessage( "Sorry the job has been cancelled" );
}</pre>
&nbsp;
<p style="text-align: left;">It wouldn't be fun if we just left it like that, so let's add another <em>if</em> using <em>else if</em> to check <em>if</em> seconds is 33 or 44 and if it is we are going to double the cost of his job and leave a comment in the job log so we know what happened.</p>

<pre>else if ( seconds == 33 || seconds == 44 ) {
 	actions.job.setCost( inputs.job.cost * 2 );
 	actions.job.addComment( "Cost doubled for Halloweeen trick" )
}</pre>
&nbsp;
<p style="text-align: left;">Now, we can end this with an <em>else</em> to catch anything else and leave it blank in an attempt to make him think it's just random. We could of course use <em>actions.job.convertToGrayscale()</em> to convert the other jobs to Grayscale if we wanted to, but that might give away the game.</p>

<pre>else {
	// Don't do anything
}</pre>
&nbsp;
<p style="text-align: left;">That is it! You've made it to the end of the first monthly script, and hopefully you have some ideas of what you could do in your environment for a little bit of fun. The full script is below and if you have any ideas for a future script get in touch and let us know.</p>

<h4 style="text-align: left; line-height: 1.5em;">If you have your own requirements for a PaperCut 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></h4>
<pre>/*
* Halloween User Trick
*
* Cancel or charge double for some jobs from a certain user
*
* Read more at https://staging.selectec.com/script-of-the-month-1-halloween-trick/
*/

function printJobHook(inputs, actions) {

  if ( !inputs.job.isAnalysisComplete ) {
    // No job details yet so return.
    return;
  }

  // The user we want to mess with
  var username = "Ross";
  // Get the seconds from the time the job was sent
  var seconds = inputs.job.date.getSeconds();

  if ( inputs.job.username == username ) {
    // If 11 or 22 seconds
    if ( seconds == 11 || seconds == 22 ) {
      // Cancel the job and let the user know
      actions.job.cancel();
      actions.client.sendMessage( "Sorry the job has been cancelled" )
    // Else If seconds is 33 or 44
    } else if ( seconds == 33 || seconds == 44 ) {
      // Double the cost of his job and a comment to the job
      actions.job.setCost( inputs.job.cost * 2 );
      actions.job.addComment( "Cost doubled for Halloweeen trick" )
    } else {
      // Don't do anything
    }
  }
}
</pre>