QR Code for generating an incident with asset info

Eric148
Tera Guru

Hello all,

 

Goal:  User scans QR code on their PC/printer.  Incident creation form opens on their mobile device (after signing in) with the PC/printer asset info filled in already.

Restrictions:  Mobile app cannot be used.  Users have no roles.  Asset is not necessarily assigned to user.

 

In testing, I have been able to create a UI Action on an hardware asset page that opens the incident creation form where that asset's name is already populated when the form opens.  However, I need this to direct end users to the Service Portal in instance Self-Service -> Service Catalog -> Can We Help You? -> Create Incident possibly.

 

Any thoughts?

 

Thank you,

1 ACCEPTED SOLUTION

jMarshal
Mega Sage
Mega Sage

The "create incident" in the service catalog is actually a record producer...so you'll need the url of your record producer....and then append with arguments to pre-populate values in the URL.

This is described in pretty good detail here: 3 Ways to Populate Values in ServiceNow via the UR... - ServiceNow Community

You'll be looking at "option 2" as it's a record producer you want, not the incident table form.


Just hardcode the values for each QR code into the URL you are generating...and keep in mind that this is hardcoded...so any changes on "either side of the equation" will need manual updates/fixes (printing a new QR code).

For instance, if you change the variable name of where you're sticking the "Hardware Type" (assuming that's one thing you're looking for in the record producer) or if the value of that changes from "HP" to "Hewlett-Packard"...you'll need to update the QR code in either case....or if the hardware in question is replaced, it will need a new QR code (assuming you're tracking unique assets).

 

View solution in original post

9 REPLIES 9

Oh, neat - thanks for that link. I think you're barking up the right tree - and from what I can see, you do want to use "decodeURIComponent("${sysparm_url}"); ....but maybe try breaking it out of the function call for set preference...instead of embedding it?

Maybe try to set it as an independent variable in the UI Action, separately from the function and then reference the variable, and do the decode before the set preference fucntion call...
kinda like this maybe (in the UI Action):

function openQRDialogBox() {

 

var urlstring = <method 2 from the link I provided before>

alert('urlstring'); //what does it look like?

urlstring = decodeURIComponent("urlstring");
alert('urlstring'); //still good?

 

var gdw = new GlideDialogWindow('UIPAGENAME');

gdw.settitle(stuff);

gdw.setsize(stuff);

gdw.adjustbodysize();

alert('urlstring'); //just keeping an eye on it

gdw.setPreference("sysparm_url", urlstring);

alert('urlstring'); //again

gdw.render();


}

If the alert before the render has the correct url (no &amp), but problems persist -- then it probably is in the Jelly as you suspect and I'm not sure how you would go about tackling that, sorry. If that's the case, maybe the original author in that other post can help -- they do provide their email address in the thread.

I also noticed that there are 2 xml files attached to the other thread, which reference the "jquery.qrcode.min" UI Script (one is "1_jquery.qrcode.min.xml" and the other is "jquery.qrcode.min") maybe there was a published fix that wasn't mentioned in the thread (one works for url with "&" & one without?)

Hope this helps!

Thanks for the script.  I ran that through and the URL displays correctly in all of the alerts (even before the decode).

 

Looking again at the QR code thread I linked yesterday, there are actually replies about the ampersand not displaying correctly, and the solution being to use %26.  I tested it and it seems to be working!

 

Thanks again for your help,

Oh, awesome! glad to know it works...I'll bookmark this and maybe we'll use it in the future too!

HI @jMarshal , i used the same link to create qr code for assets in our company but the requirement is to add that same qr code to the qr code field on the asset which an image variable. do you have any ideas on how can i modify the existing script to run when asset is create it should auto create qr code and attach it to image variable with out any human intervention ?

BELOW IS THE CODE I TRIED


// function SendPrint() {
// var a = document.getElementsByTagName("canvas")[0].toDataURL();
// var windowContent = '<!DOCTYPE html>';
// windowContent += '<html>';
// windowContent += '<head><title>Print canvas</title></head>';
// windowContent += '<body>';
// windowContent += '<img src="' + a + '">';
// windowContent += '</body>';
// windowContent += '</html>';
// var printWin = window.open('', '', 'width=' + screen.availWidth + ',height=' + screen.availHeight);
// printWin.document.open();
// printWin.document.write(windowContent);
// printWin.document.addEventListener('load', function() {
// printWin.focus();
// printWin.print();
// printWin.document.close();
// printWin.close();

// function SendPrint() {
// var a = document.getElementsByTagName("canvas")[0].toDataURL();
// var link = document.createElement('a');
// link.href = a;
// link.download = 'canvas_image.png';
// link.click();
function SendPrint() {
var canvas = document.getElementsByTagName("canvas")[0];
var logoImg = new Image();
logoImg.src="MidcoBannerImage.jpg";
logoImg.onload = function() {
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
var logoWidth = logoImg.width;
var logoHeight = logoImg.height;

var context = canvas.getContext("2d");
context.drawImage(logoImg, (canvasWidth - logoWidth) / 2, (canvasHeight - logoHeight) / 2);

var a = canvas.toDataURL();
var link = document.createElement('a');
link.href = a;
link.download = 'canvas_image.png';
link.click();
};
}

 

Sorry, I'm not very familiar with creating the actual image to be used...but I think the thread before was generating "temporary" QR codes...not permanent ones that would be stored (attached to the record)...

There is a reply from ServiceNow Employee @SaschaWildgrube in that thread which details this, maybe have a look at the link they posted?

 

Hope this helps!