<h2 style="text-align: left;">Topical and political for this month's Advanced PaperCut Print Script</h2>
<h3 style="text-align: left; line-height: 1.5em;">The Selectec pre-sales team developed an interesting idea to use PaperCut to record people's opinions and not just their print &amp; copy history. The how will be explained below, the why is anyone's guess, but grab your coffee and let's jump in.</h3>
&nbsp;

<img class="aligncenter size-full wp-image-2569" src="https://staging.selectec.com/wp-content/uploads/2016/06/sotm_prompt.jpg" alt="sotm_prompt" width="663" height="210" />

&nbsp;

<hr />

&nbsp;

The first part of this is just setting variables as we have done before so we will set the Title for the pop-up window, the question to ask and the choices the user can pick from.
<pre>var TITLE = "Referendum on the United Kingdom's membership of the European Union";
var QUESTION = "Should the United Kingdom remain a member of the European Union or leave the European Union?";
var CHOICES = ["Remain", "Leave", "Undecided"];</pre>
&nbsp;

Now for something new we are going to set some <a href="http://www.papercut.com/products/ng/manual/common/topics/script-print-api.html#script-print-actions-client-stdopts" rel="noopener noreferrer">options for the prompt</a> which will help us hide the job details and set the default choice.
If you wanted to change the default option to something else you can modify the value that has been set for defaultChoice but you need to make sure it exists in your list of options.
<pre class="">var OPTIONS = {
  'defaultChoice' : 'Undecided',
  'hideJobDetails' : true,
  'dialogDesc' : QUESTION,
  'dialogTitle' : TITLE
}</pre>
&nbsp;

With the setup out of the way, all we need to do is show the prompt and then save the results so we can view them. When showing the prompt we will need to make sure we set the response to a variable, so we know what option has been selected.
<span style="line-height: 1.5;">This is a bit different to how we would normally create a prompt as we are not setting the text to display. Instead, we are simply using the Title and Description fields established in the options above.  If you did wish to include extra text you can put it between the two '.</span>
<pre>var vote = actions.client.promptForChoice('', CHOICES, OPTIONS);</pre>
&nbsp;

We now know what the user has selected and the result is saved in the "vote" variable. We could use a bunch of "if statements" and have one for each possible choice. We could then base our action on the response but as we know that the end goal is to increase a counter by 1 we can use a "for loop" to go over each of the choices until we have a match.
<pre>for (i = 0; i &lt; CHOICES.length; i++) {
  if (vote == CHOICES[i]) {
    // We will increase the number here
  }
}</pre>
&nbsp;

To save the votes, we will use the actions.utils.onCompletionIncrementNumberProperty() method that we used a couple of months ago to <a href="/script-of-the-month/script-of-the-month-7-count-virtual-queue-sheets/" rel="noopener noreferrer">track virtual queue usage</a>, but we are going to dynamically set the property by using <em>'vote.' + vote</em> this will then give us the custom property script.user-defined.vote.[USERS-CHOICE] that we can search for in the config editor by using the 'vote.' prefix.
<pre>actions.utils.onCompletionIncrementNumberProperty('vote.' + vote, 1);</pre>
&nbsp;

That is it for this month and as always the complete Advanced PaperCut Print Script is below.
<h3></h3>
<h3 style="text-align: left; line-height: 1.5em;">If you have your own requirements for an Advanced 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 getting in touch with our sales team.</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>
&nbsp;

</div>
<pre>/*
* Ask users to vote on important things like staying in the EU
*
* Read more at https://staging.selectec.com/script-of-the-month-9-everyone-has-an-opinion/
*/

function printJobHook(inputs,actions) {

  // Prompt Title
  var TITLE = "Referendum on the United Kingdom's membership of the European Union";
  // What question are we going to ask?
  var QUESTION = "Should the United Kingdom remain a member of the European Union or leave the European Union?";
  // Array of possible choices
  var CHOICES = ["Remain", "Leave", "Undecided"];

  // Dictionary containing Prompt options
  var OPTIONS = {
    'defaultChoice' : 'Undecided',
    'hideJobDetails' : true,
    'dialogDesc' : QUESTION,
    'dialogTitle' : TITLE
  }

  // Analysis has not completed return
  if (!inputs.job.isAnalysisComplete) {
    return;
  }


  // Show the prommpt and set the response to vote
  var vote = actions.client.promptForChoice('', CHOICES, OPTIONS);

  // We are not bothered by Timeouts or those who don't want to vote
  if (vote == "TIMEOUT" || vote == "CANCEL") {
    return;
  }

  // Loop choices
  for (i = 0; i &lt; CHOICES.length; i++) {
    // If vote = choice
    if (vote == CHOICES[i]) {
      // increase vote.[users-choice] by 1
      actions.utils.onCompletionIncrementNumberProperty('vote.' + vote, 1);
    }
  }
}</pre>