<h1 style="text-align: left;">PaperCut print script of the Month</h1>
<h3 style="text-align: left; line-height: 1.5em;">Like most days I was sat at work enjoying my coffee while listening to a random playlist on Spotify when my <a href="https://en.wikipedia.org/wiki/Voice_over_IP">VOIP</a> phone rings. It was one of our valued resellers who wanted us to throw some ideas at them to meet a client's requirements. What he wanted to do was set up a way that delegated print release could be optional for the students, and the PaperCut Shared Accounts would still be charged. There was a catch with this one where the users doing the releasing would be teaching assistants who move between classes.</h3>
At first, it seemed like it could be almost impossible to do this and make it optional. After about 15 minutes we decided that a PaperCut print script might be able to handle this and not get in the way of the workflow too much. Take a couple of minutes to digest this scenario and go and get your coffee before we start working it out.

&nbsp;

First, we need to work out what we want to do, and that is to present a list of users to any account in a group, and once selected let that user release the job.
Let’s start by creating an array that will store the users we will show in the popup and set the group that this will apply to.
<pre class="">var USERS = ["none", "bwayne", "tstark", "pparker", "ballen", "oqueen", "ckent"];
var GROUP = "students";</pre>
All good so far, Now we know we will want to show a popup so we might as well set a couple of variables to hold the popup message and the title.
<pre>var MESSAGE = "Please select an account below to allow that user to release your job.";
var TITLE = "Select an account";</pre>
As we only want this window to appear for the student's group we will want to check inputs.user.isInGroup() and if it isn't the group we want we will need to leave the script.
<pre>if (!inputs.user.isInGroup(GROUP)) { return; }</pre>
To display our prompt we are going to use actions.client.promptForChoice(), It will accept a message and an Array of choices which will return the selected value when the user clicks on OK.
<pre>var response = actions.client.promptForChoice(MESSAGE, USERS);</pre>
If we just used this, the popup would show the document information, and a generic title so let's set some options like hiding the job details, showing our title and setting the default choice to none.
<pre>var OPTIONS = {'dialogTitle': TITLE, 'defaultChoice': 'none', 'fieldLabel': 'Accounts', 'hideJobDetails': true};</pre>
We now need to go back and update our actions.client.promptForChoice() method to include the options we want.
<pre>var response = actions.client.promptForChoice(MESSAGE, USERS, OPTIONS);</pre>
All that is left to do now is work out how we are going to enable the other user account to release the job. To achieve this we are going to change the user that owns the print job. Usually, this would cause a problem with reporting if you wanted to know which user was sending the job but luckily for this case, it doesn't matter as the shared account will be billed.
So what is this magical method? actions.job.changeUser(), If you plan to use this make sure the users exist and if you intend to let the users manually type in the name make sure you check the input is not longer than 50 characters.

So back to the script, we will check that the response is not "none" then change the user that owns the job to whatever the value of the response happens to be.
<pre class="">if (response != 'none') {
  // Change the user
  actions.job.changeUser(response);
}
</pre>
<h3></h3>
<h3 style="text-align: left;"></h3>
<h3 style="text-align: left;">That is it for this month and as always the complete PaperCut print script is below.</h3>
<h3 style="text-align: left; line-height: 1.5em;">We can help you with print scripts! You can find out more about what we offer <a href="https://staging.selectec.com/select/scripting/">here</a>. So, if you have your own requirements for a print script and you don’t have the time or in-house experience to make it then simply contact us.</h3>
<div class="well well-lg">
<h3 style="text-align: center;">Get in touch today | <a href="mailto:sales@selectec.com">sales@selectec.com</a></h3>
</div>
<pre>/*
* Select Release Account
*
* Read more at https://staging.selectec.com/papercut-print-script-month-13-select-release-account/
*/
function printJobHook(inputs, actions) {

  // Users that can be selected from the dropdown
  var USERS = ["none", "bwayne", "tstark", "pparker", "ballen", "oqueen", "ckent"];

  // Group to apply script to
  var GROUP = "students";

  // Message to show in the popup
  var MESSAGE = "Please select an account below to allow that user to release your job.";

  // Popup Title
  var TITLE = "Select an account";

  // Popup options
  var OPTIONS = {'dialogTitle': TITLE, 'defaultChoice': 'none', 'fieldLabel': 'Accounts', 'hideJobDetails': true};

  // As always we will wait for analysis just to make sure there are no problems
  if (!inputs.job.isAnalysisComplete) { return; }

  // If user is not in the students group exit the script
  if (!inputs.user.isInGroup(GROUP)) { return; }

  // Get the response from the prompt and set the default value to none
  var response = actions.client.promptForChoice(MESSAGE, USERS, OPTIONS);

  // If the selection is not none
  if (response != 'none') {
    // Change the user
    actions.job.changeUser(response);
  }

  // We don't need to do anything here
}
</pre>