
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 10-05-2018 11:14 AM
This is my next article on the subject "barcode labels" and this one is about how to do a "clean" barcode printout on a Zebra label printer.
The label print in this case is done by using Zebra's Browser Print application and works like a kind of "silent printing".
I've come up with a solution that works and is pretty easy to set up (when you finally know how ;-)).
To start with i use Zebra Browser Print, a local service you install separately on thoose machines hosting the printer. It should also be possible to print on a network installed printer but i haven't tested that yet.
The aim for this article is to show how to connect to a physical device in some extent not known by the web application itself.
We will use an UI Action to be able to do the print using Zebra's ZPL language.
We use the Asset table/form (alm_asset) as an use case for demo purpose.
At this very moment i'm still having some timing issues with multiple print (from a list view)...but single print from the form works as it should 🙂
Steps to get this running:
- Download the Zebra Browser Print install application. Install the application service as described in the installation notes (attached). Localize the library "\ZebraBrowserPrintDocsWebCodeExamples\lib" and upload the script "BrowserPrint-1.0.4.min" (as it is, no "prettify") to your instance as a UI Script.
Tip: Create an empty UI Script (naming it "BrowserPrint-1.0.4.min") and save the UI Script not pasting/inserting the script. From list view add "Script" field and paste the code using the list view. This preventing syntax check and being able to save when using the form view. - If you want to use the UI Script from different forms etc. make it global (Check "Global" field) otherwise leave it unchecked and load the UI Script in an OnLoad Client Script using ScriptLoader.
In this example i'll leave it unchecked and use ScriptLoader described below. - Create a UI action "Print Zebra Barcode" as shown below.
Script:
function printZebraLabel() { try { // Using Zebra Browser Print var labelText = ""; var available_printers = null; var selected_category = null; var default_printer = null; var selected_printer = null; var format_start = "^XA^LL200^FO80,50^A0N36,36^FD"; var format_end = "^FS^XZ"; var default_mode = true; // Check if printing is triggered from the form or the list view var sysIds = []; if (typeof g_list !== 'undefined') { sysIds = g_list.getChecked().split(","); } // Check if default printer is set jslog("Connecting to default Zebra printer..."); BrowserPrint.getDefaultDevice("printer", foundDevice, deviceError); } catch(err) { jslog('A JavaScript runtime error occurred: ' + err.message); } function userCallback(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); answer = JSON.parse(answer); if (answer) { jslog("Printing barcode with values: Model = " + answer.model.displayValue + ", Serial no: " + answer.serial_number.value); printLabel(answer.model.displayValue, answer.serial_number.value); } } function printLabel(model, serial) { try { // Create Zebra label using ZPL language labelText = "^XA"; // Start command labelText += "^CF0,20"; // Font size labelText += "^FO20,115^FDModel: " + model + "^FS"; // Set Model labelText += "^BY2,3,74^FT37,84^B3N,N,,Y,N"; // Set barcode format labelText += "^FD" + serial + "^FS"; // Set barcode data labelText += "^PQ1,0,1,Y^XZ"; // End command selected_printer.send(labelText, printComplete, printerError); } catch(err) { jslog('A JavaScript runtime error occurred: ' + err.message); } } function foundDevice(printer) { try { default_printer = printer; if ((printer != null) && (printer.connection != undefined)) { selected_printer = printer; jslog("Found Zebra printer: " + printer.name + " connected via: " + printer.connection); // Check if printing is triggered from the form or the list view if (sysIds.length > 0) { for (var i = 0; i < sysIds.length; i++) { var ga = new GlideAjax('AdvaniaUtils'); ga.addParam('sysparm_name','ajaxClientDataHandler'); ga.addParam('sysparm_tablename','alm_asset'); // Table name ga.addParam('sysparm_sysid', sysIds[i]); // Sysid ga.addParam('sysparm_fieldnames','model,serial_number'); // Field names we want to retrieve ga.getXML(userCallback); } } else { printLabel(g_form.getDisplayValue('model'), g_form.getValue('serial_number')); } } else { alert("No default Zebra printer is configured. Please right-click on Zebra Browser Print icon in system tray and set a default Zebra printer."); } } catch(err) { jslog('A JavaScript runtime error occurred: ' + err.message); } } function deviceError(errorMessage) { try { alert("An error occured while attempting to connect to your Zebra Printer. You may not have Zebra Browser Print installed, installed SSL certificate or it may not be running. Install Zebra Browser Print, or start the Zebra Browser Print Service, and try again! Error message: " + errorMessage); } catch(err) { jslog('A JavaScript runtime error occurred: ' + err.message); } } function sendData() { jslog("Printing on Zebra..."); selected_printer.send(format_start + labelText + format_end, printComplete, printerError); checkPrinterStatus( function (text){ if (text == "Ready to Print") { selected_printer.send(format_start + labelText + format_end, printComplete, printerError); } else { printerError(text); } }); } function checkPrinterStatus(finishedFunction) { selected_printer.sendThenRead("~HQES", function(text){ var that = this; var statuses = []; var ok = false; var is_error = text.charAt(70); var media = text.charAt(88); var head = text.charAt(87); var pause = text.charAt(84); // check each flag that prevents printing if (is_error == '0') { ok = true; statuses.push("Ready to Print"); } if (media == '1') statuses.push("Paper out"); if (media == '2') statuses.push("Ribbon Out"); if (media == '4') statuses.push("Media Door Open"); if (media == '8') statuses.push("Cutter Fault"); if (head == '1') statuses.push("Printhead Overheating"); if (head == '2') statuses.push("Motor Overheating"); if (head == '4') statuses.push("Printhead Fault"); if (head == '8') statuses.push("Incorrect Printhead"); if (pause == '1') statuses.push("Printer Paused"); if ((!ok) && (statuses.Count == 0)) statuses.push("Error: Unknown Error"); finishedFunction(statuses.join()); }, printerError); } function printComplete() { jslog("Zebra bar code printing complete."); } function printerError(text) { alert("An error occurred while printing on Zebra printer. Please check if Zebra printer is online and try again." + text); } }
- Finally don't forget to install SSL certificate: https://localhost:9101/ssl_support
- 17,589 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How to find 'AdvaniaUtils' Script Include?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
I was recently implementing a Zebra printing solution based on Mikhael's solution and I created a new Script Include for the Ajax call based on the following Community blog post which describes implementing a "ajaxClientDataHandler" function which can be used by the Zebra UI Action.
Community blog post "How to Write Smart GlideAjax Quickly":
https://community.servicenow.com/community?id=community_blog&sys_id=53333bbddbb813404837f3231f9619d7
Hope this helps.
Btw, thank you
Best regards,
Ingimar
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Were you ever able to figure out how to print from list view? The script looks like it should work but for some reason I am getting an error when I click the UI Action in list view.
Level: Error
Source: com.glide.ui.ServerletErrorListener
Message: Script: AdvaniaUtils not found in scope: global, and HTTP Processor class not found: com.glide.processors.xmlhttp.AdvaniaUtils: no thrown error
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
During my troubleshooting I found that the BrowserPrint is not loaded when in list view. I have tried adding the client script but it fires on the form not the list.
I also tried to run the scriptLoader from the UI action where the action determines if in form or list view but that didn't work either.
if (typeof g_list !== 'undefined') {
sysIds = g_list.getChecked().split(",");
try{
scriptLoader.getScripts('BrowserPrint.jsdbx', function () {});
}
catch(err){
jslog('A JavaScript runtime error occurred: ' +err.message);
}
}

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Aaron.
Printing from list view was not a requirement for our use case so we left it out.
Maybe GlideUIScripts can help in your case?
See "Call a UI script from client-side code":
https://docs.servicenow.com/bundle/quebec-application-development/page/script/client-scripts/concept/c_UIScripts.html
And:
https://docs.servicenow.com/bundle/quebec-application-development/page/app-store/dev_portal/API_reference/GlideUIScripts/concept/GUIScriptsAPI.html#GUIScriptsAPI
Best regards,
Ingimar

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Glad it helped, thanks 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I am not sure why it didn't work before but it works now. Just used the
scriptLoader.getScripts('BrowserPrint.jsdbx', function () {}); to load the BrowserPrint Script Include.
Had to write my own util using the guide that
https://community.servicenow.com/community?id=community_blog&sys_id=53333bbddbb813404837f3231f9619d7
Getting the barcodes to print was easy once the util was written correctly. I am sure there was a cleaner way to do it but I had to write a function for each field that I wanted to pull over. I will work on it being one function with table name and field sent over to the function and loop through each field passed from UI action/client script.
Thank you all for your assistance.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
We ship several items out from our service desk from new hire computers to empty boxes for separations to ship their gear back. I was hoping that I could create a button on these various catalog tasks to generate a Fedex ship label, and then print the label on a local ZPL 505, vs copying data from SN into Fedex, generating the label, and then manually copying data back into SN such as tracking numbers.
I have been playing with the "Create Shipment" API over at Fedex (https://developer.fedex.com/api/en-us/catalog/ship/v1/docs.html#operation/Create%20Shipment) and have been able to generate the label using REST API from SN. This creates successfully and I am given the a URL OR an encoded label depending on which "labelResponseOptions" I select. For the URL I can get it to generate a PDF or PNG, but that isn't what I am looking for, I would like to leverage the doc_tab option of our thermal printer formatting.
In short, if I change the output to URL_ONLY and imagetype of ZPLII, I get a URL that essentially downloads a ZPL encoded file to my computer. I can then upload that to labelary.com and convert it to show what the label would look like, so I know it is working properly, but I have no real way to then convert this to a print job. I would love to convert this project into working for this if at all possible. Appreciate any assistance you can offer on this.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I don't want to solve the problem if there is a better way to do it, but I was able to return the encodedLabel as a variable, and then I can Base64 decode it all within ServiceNow. So my next step would be to somehow render that raw zpl code and output it to a printer. I think that might be my quickest way to resolution, but again, happy to hear other solutions, or how to do what I am proposing.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Ok, I was able to get it printing from SN, but now I need to verify the errors work. It seems to always say "Ready to Print" and then prints, but I opened the head of the printer and it still says 'printed successfully', which I know isn't true, so somehow it isn't reading the alert section. Any help here would be appreciated.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi All,
We have similar requirement but want to save this barcode as an attachment or paste it on ticket and then mail to customer. If you can please help me out how we can achieve it without making use of UI fromatters ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
An update on my project and clarification on my requirements. I was interested in having Service Now generate my fedex shipping label and then print it out. I was able to successfully generate the ZPL code and store it on the form locally from an API call to Fedex Ship API, and then created a UI action to print the labels to the thermal printer. Thanks all for the help on this.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The main issue being that I cannot retrieve the 'text' result of the printer. So starting with the function around line 117 of your code it is looking for variable: text, and outputs the status.
Line 105 says: if (text == "Ready to Print") which again works if I'm local to that device, but if I'm on the VPN, text is an empty variable.
The good news is that the browser does detect the printer and can connect to it, but always throws the error:
"An error occurred while printing on Zebra printer. Please check if Zebra printer is online and try again."
It seems like it isn't passing this back to the browser somehow.
Any thoughts on what this might be?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I was able to streamline the loading of the BrowserPrint UI Script which eliminates the need for the Client Script. In the UI Action, change onclick function to loadScript() and use this function before the printZebraLabel script.
function loadScript(){
try{
ScriptLoader.getScripts('BrowserPrint.jsdbx', printZebraLabel);
} catch(err){
jslog('A JavaScript runtime error occurred: ' + err. Message);
}
}
this also allows for calling of BrowserPrint created and packed with a scoped application.
function loadScript(){
try{
ScriptLoader.getScripts('myscope.BrowserPrint.jsdbx', printZebraLabel);
} catch(err){
jslog('A JavaScript runtime error occurred: ' + err.message);
}
}
Hope this helps someone.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle - Could you please let me know how you saved the ZPL code to the ServiceNow record as when I do LABEL in "labelResponseOptions" and ZPLII in "imageType" then it provides me the base64 encoded label instead of the ZPL code
However when i do LABEL as "URL_ONLY" it gives me a URL which saves a file of ZPL code which I am able to save onto my local machine
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@anubhavkapoor76 I ended up creating a field for the JSON parsed response for the label data. I have both options in my instance on a form I created to select either print label locally which would generate the ZPL code OR I could select URL and it would do that and pull the URL down.
The only problem I had, but didn't have any way of solving was trying to go and retrieve the URL output as a PDF. The URL expires after 12 hours or something, so in my ideal world in those cases, I would generate the PDF, then have SN go retrieve that URL and save the output as a PDF so that it could be used after the URL expired.
Let me know if my earlier portion helps, or if you know how to make the other thing happen.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Mikael at Advan - Thanks for posting this.
However when i click on the UI action I always get the message that "Zebra bar code printing complete"
I get the below message in console:
In your foundDevice() function when i put jslog the sysIDs length is 0 (i remember it was more than 0 last time)
Also I have not created any SI - "AvantiaUtils" . Not able to call that SI now as there is no error.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle - You are absolutely correct on that PDF thing from URL. I was trying to pull that PDF earlier from the URL but could not do so - hence I gave up.
In your earlier case - I am trying to print the label locally which could generate the ZPL code - so few questions on it.
a) How do you convert the base64 encoded label to ZPL format from Ship API response JSON.
I am using Ship API and passing the below options in Request body:
In Response I am getting the base 64 and not ZPL format:
Thanks once again for all your help on this.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@anubhavkapoor76 ah got it, sorry, so I'm just running:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle - Thank you so much. That was helpful indeed!
Could you comment on one last missing piece for me - "how to send this ZPL code to the thermal printer"?
When i click on the UI action I always get the message that "Zebra bar code printing complete"
I get the below message in console:
In your foundDevice() function when i put jslog the sysIDs length is 0 (i remember it was more than 0 last time)
Also I have not created any SI - "AvantiaUtils" . Not able to call that SI now as there is no error.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@anubhavkapoor76 Glad that was helpful, I was on that other site tweaking my payload to ensure it would line up.
As for the printing thing, I had the same issue using the code listed here in this article. I ended up going through it several times. I have no idea if this is remotely the right way to do it, or if it is even efficient, but this is what I ended up doing with my UI Action on the form itself. Keep in mind, I'm dropping the ZPL code to a field on the form for easier retrieval.
function printOutboundLabel() {
var outLabelSuccess = 0;
ScriptLoader.getScripts('BrowserPrint.jsdbx', function() {});
try {
// Using Zebra Browser Print
var labelText = "";
var available_printers = null;
var selected_category = null;
var default_printer = null;
var selected_printer = null;
var format_start = "^XA^LL200^FO80,50^A0N36,36^FD";
var format_end = "^FS^XZ";
var default_mode = true;
// Check if default printer is set
//alert("Connecting to default Zebra printer...");
BrowserPrint.getDefaultDevice("printer", foundDevice, deviceError);
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
function foundDevice(printer) {
try {
default_printer = printer;
if ((printer != null) && (printer.connection != undefined)) {
selected_printer = printer;
//alert("Found Zebra printer: " + printer.name + " connected via: " + printer.connection);
var labelText = g_form.getValue('u_fedexoutgoinglabel');
try {
sendData(labelText);
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
} else {
alert("No default Zebra printer is configured. Please right-click on Zebra Browser Print icon in system tray and set a default Zebra printer.");
}
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
}
function deviceError(errorMessage) {
try {
alert("An error occured while attempting to connect to your Zebra Printer. You may not have Zebra Browser Print installed, installed SSL certificate or it may not be running. Install Zebra Browser Print, or start the Zebra Browser Print Service, and try again! Error message: " + errorMessage);
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
}
function sendData(labelText) {
//alert("Printing on Zebra...");
//selected_printer.send(labelText, printComplete, printerError);
checkPrinterStatus(function(text) {
if (text == "Ready to Print") {
selected_printer.send(labelText, printComplete, printerError); //UNCOMMENT TO PRINT
} else {
printerError(text);
}
});
}
function checkPrinterStatus(finishedFunction) {
selected_printer.sendThenRead("~HQES",
function(text) {
var that = this;
var statuses = [];
var ok = false;
var cleanText = text.replace(/\D+/g, '');
jslog(cleanText);
var is_error = cleanText.charAt(0);
var media = cleanText.charAt(16);
//var head = cleanText.charAt(87);
//var pause = cleanText.charAt(16);
//jslog("Text: " + text + " is_error: " + " media: " + media + " head: " + head + " pause: " + pause);
//alert("Text: " + text + " is_error: " + " media: " + media + " head: " + head + " pause: " + pause);
// check each flag that prevents printing
if (is_error == '0') {
ok = true;
statuses.push("Ready to Print");
}
if (media == '1')
statuses.push("Paper out");
if (media == '2')
statuses.push("Ribbon Out");
if (media == '4')
statuses.push("Media Door Open");
if (media == '8')
statuses.push("Cutter Fault");
/*
if (head == '1')
statuses.push("Printhead Overheating");
if (head == '2')
statuses.push("Motor Overheating");
if (head == '4')
statuses.push("Printhead Fault");
if (head == '8')
statuses.push("Incorrect Printhead");
if (pause == '1')
statuses.push("Printer Paused");
*/
if ((!ok) && (statuses.Count == 0))
statuses.push("Error: Unknown Error");
finishedFunction(statuses.join());
}, printerError);
}
function printComplete() {
var outLabelSuccess = 1;
if (g_form.getValue('u_fedexreturnlabel') != '') {
printReturnLabel(outLabelSuccess);
} else {
alert("Outbound label printed successfully.");
}
}
function printerError(text) {
alert("An error occurred while printing on Zebra printer. Please check if Zebra printer is online and try again. " + text);
}
}
I had to retrieve the ZPL, and then feed it through the 'check printer status'. The codes on my older zebra were different than were listed here. I commented a bunch of lines in that function and dumped its response out to see what it was saying. I would then open the printer, or give it an empty spool of labels to get the various error codes and wrote my own status logic and returned various results.
Note, on mine, we do a lot of round trip shipping, so ended up creating a function that would print the outbound AND return label in the same shot. The other function looks the same, but if both fields are populated, then I press that button and 2 labels print immediately.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle - Reaching out to you again as you are the most vocal on this post
I am facing an issue when i click on "Print Zebra label" button. Have placed an alert box and this error seems to pop out from function sendData()
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@anubhavkapoor76 no problem, happy to help of course. My first attempt did the same thing, in this case "text" is a variable I used, so it being 'not defined' is something you will need to dig through and figure out where it isn't defined properly. I can't see your code, so would assume it was changed or dropped from what I sent.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle Here is my code.
function printZebraLabel() {
//Begin Actual code
var outLabelSuccess = 0;
ScriptLoader.getScripts('BrowserPrint-1.0.4.min.jsdbx', function() {});
try {
// Using Zebra Browser Print
var labelText = "";
var available_printers = null;
var selected_category = null;
var default_printer = null;
var selected_printer = null;
var format_start = "^XA^LL200^FO80,50^A0N36,36^FD";
var format_end = "^FS^XZ";
var default_mode = true;
// Check if default printer is set
//alert("Connecting to default Zebra printer...");
BrowserPrint.getDefaultDevice("printer", foundDevice, deviceError);
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
function foundDevice(printer) {
try {
alert("Printer:" + printer);
default_printer = printer;
if ((printer != null) && (printer.connection != undefined)) {
selected_printer = printer;
alert("Found Zebra printer: " + printer.name + " connected via: " + printer.connection);
//Anu - Take the custom field which contains ZPL label
//var labelText = g_form.getValue('u_fedexoutgoinglabel');
//Call script include
var ga = new GlideAjax('global.decodeUtil'); //Scriptinclude
ga.addParam('sysparm_name', 'decodeZPL'); //Method
//ga.addParam('userId', user); //Parameters
ga.getXMLAnswer(getResponse);
function getResponse(response) {
//console.log(response);
//var res = JSON.parse(response);
//console.log(res);
//jslog("labelText:" + response);
labelText = response;
}
setTimeout(function() {
console.log("labelText1:" + labelText);
}, 10000);
try {
sendData(labelText);
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
} else {
alert("No default Zebra printer is configured. Please right-click on Zebra Browser Print icon in system tray and set a default Zebra printer.");
}
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
}
function deviceError(errorMessage) {
try {
alert("An error occured while attempting to connect to your Zebra Printer. You may not have Zebra Browser Print installed, installed SSL certificate or it may not be running. Install Zebra Browser Print, or start the Zebra Browser Print Service, and try again! Error message: " + errorMessage);
} catch (err) {
alert('A zebra JavaScript runtime error occurred: ' + err.message);
}
}
function sendData(labelText) {
//alert("Printing on Zebra...");
//alert("labelText:"+labelText);
//selected_printer.send(labelText, printComplete, printerError);
console.log("Text:" + text);
checkPrinterStatus(function(text) {
if (text == "Ready to Print") {
jslog("labelText2:" + labelText);
selected_printer.send(labelText, printComplete, printerError); //UNCOMMENT TO PRINT
} else {
printerError(text);
}
});
}
function checkPrinterStatus(finishedFunction) {
selected_printer.sendThenRead("~HQES",
function(text) {
var that = this;
var statuses = [];
var ok = false;
var cleanText = text.replace(/\D+/g, '');
jslog(cleanText);
var is_error = cleanText.charAt(0);
var media = cleanText.charAt(16);
//var head = cleanText.charAt(87);
//var pause = cleanText.charAt(16);
//jslog("Text: " + text + " is_error: " + " media: " + media + " head: " + head + " pause: " + pause);
//alert("Text: " + text + " is_error: " + " media: " + media + " head: " + head + " pause: " + pause);
// check each flag that prevents printing
if (is_error == '0') {
ok = true;
statuses.push("Ready to Print");
}
if (media == '1')
statuses.push("Paper out");
if (media == '2')
statuses.push("Ribbon Out");
if (media == '4')
statuses.push("Media Door Open");
if (media == '8')
statuses.push("Cutter Fault");
/*
if (head == '1')
statuses.push("Printhead Overheating");
if (head == '2')
statuses.push("Motor Overheating");
if (head == '4')
statuses.push("Printhead Fault");
if (head == '8')
statuses.push("Incorrect Printhead");
if (pause == '1')
statuses.push("Printer Paused");
*/
if ((!ok) && (statuses.Count == 0))
statuses.push("Error: Unknown Error");
finishedFunction(statuses.join());
}, printerError);
}
function printComplete() {
var outLabelSuccess = 1;
if (g_form.getValue('u_fedexreturnlabel') != '') {
printReturnLabel(outLabelSuccess);
} else {
alert("Outbound label printed successfully.");
}
}
function printerError(text) {
alert("An error occurred while printing on Zebra printer. Please check if Zebra printer is online and try again. " + text);
}
//End Actual code
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle - I see that your code also does not have the "text" variable defined in the UI Action script
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@anubhavkapoor76 The problem is - that error message is written in 4 different times. To do your best debugging, I would locate those 9 alert messages first and then modify them slightly, even if its just adding a number to the print message. That way we will know where it is failing and in what function to better figure it out.
Also, you kept in my code for printing the return label. I doubt that's the issue, but who knows.
This:
function printComplete() {
var outLabelSuccess = 1;
if (g_form.getValue('u_fedexreturnlabel') != '') {
printReturnLabel(outLabelSuccess);
} else {
alert("Outbound label printed successfully.");
}
}
Should probably just be:
function printComplete() {
alert("Outbound label printed successfully.");
}
Unless you duplicated the function and updated it accordingly. Also, did you create fields on your form to match mine?
Ultimately, you are correct, I didn't define 'text' the variable, but unclear how its working.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@payerle we ended up printing it manually, as the code did not worked!
But thanks for all your help
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@anubhavkapoor76 sorry you had to print manually - were you ever able to update the alerts to see where the failure was occurring exactly? Happy to help further, but would need to see the updated code and new alerts.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @payerle and @anubhavkapoor76 ,
Sorry for me not answering, i've totally missed out the notifications on this post...
I'm glad the article helped in some extent and that you together solved your issues 🙂
Kind regards,
/Mikael
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mikael,
Thanks for sharing.
I am looking to implement this solution.
Could you please help me with the scripts mentioned here
Download the Zebra Browser Print install application. Install the application service as described in the installation notes (attached). Localize the library "\ZebraBrowserPrintDocsWebCodeExamples\lib" and upload the script "BrowserPrint-1.0.4.min" (as it is, no "prettify") to your instance as a UI Script. Could you pleae locaate me the installation notes ?
Where do I find teh script to upload into UI script ?
Does this connect requires a MID to connect to servicenow.
Currently we have a printer connected to the physical machine via USB. How do I trigger this print reques from servicneow?
Thanks,
SOwmya