Printing out barcodes?

Benjamin Nuttin
Giga Expert

We would like the ability to print out asset receiving forms to send to our vendors. These forms would have data from the system, mostly in the form of text fields and the like, but they would also have barcodes. These would simply be a representation of the asset serial numbers in a special "barcode" typeface. Has anyone done this before? Any idea how we can implement this? Thanks!!

1 ACCEPTED SOLUTION

That's pretty cool! It worked well for me. I put the code39.js code in a UI Script named "code39" and then included it on a UI Page with the HTML:



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:include_script src="code39.jsdbx"/>
<div id="externalbox" style="width:5in">
<div id="my_barcode" />
</div>
</j:jelly>


And then UI Page's Client Script is:



$("my_barcode").innerHTML=DrawCode39Barcode("123456789",1);


View solution in original post

22 REPLIES 22

I tried it as a UI Script and it worked great. thanks for the suggestion.


Hi Eric,

I'm trying to generate the barcode based on a parameter fed into the UI page. Is there a way to accept get the parameter out of the url and into the client script, in order to generate a barcode?


Figured it out, thanks to a bit of code that Mark Stanger shared:

http://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/

Here's a UI action that opens the UI page and passes a field "Unique Server ID" as a parameter:



current.update();
gs.setRedirect("barcode_generator.do?sysparm_encode=" + current.u_unique_server_id);


The UI page is still the same as what Eric posted, and but with this as the client script:



var encode = getParmVal('sysparm_encode');
$("my_barcode").innerHTML=DrawCode39Barcode(encode,0);

function getParmVal(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec( window.location.href );
if(results == null){
return "";
}
else{
return results[1];
}
}


Here's a link with the output:
https://demogy.service-now.com/barcode_generator.do?sysparm_encode=SRV00000001


Hi All,

I generated barcode for my assets using the above mentioned UI script and UI Page. Can I generate barcodes for the complete list in one go and print the same.
Right now, I click on the button on cmdb_ci record which generate barcode for that particular asset only.
Is there a way, from the list itself, I can generate and print my barcodes in one go(for 20 assets or more based on selected rows).


You should be able to use g_list.getChecked() in a list UI Action to get the list of checked items and then use that to generate your page with the required barcodes. Try searching your UI Actions for scripts containing "g_list.getChecked()" for examples.

http://wiki.service-now.com/index.php?title=GlideList2_(g_list)#getChecked