
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-12-2018 07:25 AM
Recently, I re-discovered processors in ServiceNow. 🙂
Now I used a processor to implement the functionality behind so-called "dynamic QR Codes".
First of all: there is nothing dynamic about the QR Code itself: it contains a specific coded information and this is never going to change. However, the result can be dynamic by changing what happens after the QR code was scanned.
The advantages are obvious: one could deactivate QR codes or change the page that it opens.
Outline of the functionality:
So what do we need?
1. The QR code. Easy: there are many free QR Code generators available online: just type in your URL and it instantly generated the code. One could even create QR codes in ServiceNow by using code from open source projects.
2. a lookup table: a simple one that maps the URL parameter value to the respective record in the database - so 2 columns are enough
3. a processor: doing the actual job of looking up the correct information based on the mapping and redirecting the browser to the correct resource.
1. gr-code-generator.com gives me the following QR Code for
https://...service-now.com/processme.do?qrid=12X89Y (INVALID URL)
2. this is a simple lookup table:
- the qrid is the hard-coded parameter from the QR code passed into the processor
- the mapping information is the record we look for. Here we search for a user record.
one could also make this lookup table more dynamic by creating a 3rd column for the table to look into or by adding an "active" column.
3. as you can see in 1., this processor is called "processme".
Let's say we look up the user "firstname.lastname1" in table "sys_user" and this record has a column that contains a resource pointing to the user's public profile (in our case the column "u_profile" contains the value "training-and-certification.html")
Processor's script:
(function process(g_request, g_response, g_processor) {
var qrid = g_request.getParameter("qrid"); // get parameter value from URL
var userinfo = resolveMapping(qrid);
// redirecting to a resource specified in the mapped record
g_processor.redirect("https://www.servicenow.com/services/" + userinfo);
function resolveMapping(qrid) {
// looking up the mapping
var gr = new GlideRecord("u_map_url");
gr.addQuery("u_qrid", qrid);
gr.query();
if (gr.next()) {
var rec = new GlideRecord("sys_user");
// looking up the mapped information
rec.addQuery("user_name",gr.getValue("u_mapping"));
rec.query();
if (rec.next()) {
// creating some string with info
var profile = rec.getValue("u_profile");
}
return profile;
}
}
})(g_request, g_response, g_processor);
The redirect function is especially handy to implement this functionality.
A word about security:
Problably, you will have to make the processme page public if you want unauthorised users to use this feature: use the "Public Pages" module. (Careful: that meany anybody can access the processor!)
Make sure you have Access Controls in place and consider using the Anti-CSRF token:
https://docs.servicenow.com/bundle/london-application-development/page/script/processors/task/t_Secu...
Let me know what you think
- 1,256 Views