PaperCut Print Script of the Month #13 Select Release Account
PaperCut print script of the Month
Like most days I was sat at work enjoying my coffee while listening to a random playlist on Spotify when my VOIP 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.
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.
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.
var USERS = ["none", "bwayne", "tstark", "pparker", "ballen", "oqueen", "ckent"]; var GROUP = "students";
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.
var MESSAGE = "Please select an account below to allow that user to release your job."; var TITLE = "Select an account";
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.
if (!inputs.user.isInGroup(GROUP)) { return; }
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.
var response = actions.client.promptForChoice(MESSAGE, USERS);
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.
var OPTIONS = {'dialogTitle': TITLE, 'defaultChoice': 'none', 'fieldLabel': 'Accounts', 'hideJobDetails': true};
We now need to go back and update our actions.client.promptForChoice() method to include the options we want.
var response = actions.client.promptForChoice(MESSAGE, USERS, OPTIONS);
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.
if (response != 'none') { // Change the user actions.job.changeUser(response); }
That is it for this month and as always the complete PaperCut print script is below.
We can help you with print scripts! You can find out more about what we offer here. 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.
Get in touch today | sales@selectec.com
/* * Select Release Account * * Read more at http://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 }