Skip to content

Commit d538696

Browse files
authored
Added QR Generator for Assets In UI Action Folder (#2597)
* Create ui-action-script.js Created folder and added ui action script file * Uploaded UI ACtion Image Added Image which shows ui action * Create ReadMe.md Added Readme file * Update ReadMe.md Removed ui action code from Readme file
1 parent fc3a3b6 commit d538696

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 🧩 ServiceNow Asset QR Code Generator (UI Action)
2+
3+
This repository contains a **ServiceNow UI Action** script that generates and displays a QR Code for an Asset record from list view.
4+
When the user selects a record and clicks the UI Action, a modal window pops up showing a dynamically generated QR Code that links to asset details.
5+
6+
7+
A supporting **Script Include** (server-side) is required in your ServiceNow instance but **is not included** in this repository.
8+
At the bottom of file , a sample Script Include Code is given , check for the reference.
9+
10+
---
11+
12+
## 🚀 Features
13+
14+
- Generates a QR Code for the selected Asset record.
15+
- Displays the QR Code inside a ServiceNow modal (`GlideModal`).
16+
- Uses **QrIckit API** for quick and free QR code generation.
17+
- Clean, modular client-side code that integrates seamlessly with UI Actions.
18+
- Includes a `qr-code-image` file showing example QR Code generated.
19+
20+
---
21+
22+
## 🧠 How It Works
23+
24+
1. The `onClickQR()` function is triggered when the user clicks a UI Action button.
25+
2. It calls `generateQRCodeForAsset(sys_id)` and passes the record’s `sys_id`.
26+
3. A `GlideAjax` request fetches asset data from a **Script Include** on the server.
27+
4. That data is encoded and sent to the **QrIckit** API to generate a QR Code image.
28+
5. A ServiceNow modal (`GlideModal`) displays the generated QR Code to the user.
29+
30+
---
31+
32+
33+
**Note :**
34+
1) As the UI action calls a Script Include , in this folder no script include is present
35+
2) You can modify script include part as required(i.e Which fields are to be shown when QR is scanned)
36+
3) A sample Client Callable Script-Include is given here.
37+
38+
``` Script Include Code
39+
var GenerateAssetQR = Class.create();
40+
GenerateAssetQR.prototype = Object.extendsObject(AbstractAjaxProcessor, {
41+
getAssetQRData: function() {
42+
var sys_id = this.getParameter('sysparm_sys_id');
43+
var asset = new GlideRecord('alm_asset');
44+
if (asset.get(sys_id)) {
45+
return 'Asset: ' + asset.name + ', Serial: ' + asset.serial_number;
46+
}
47+
return 'Invalid asset record.';
48+
}
49+
});
50+
```
87.7 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function onClickQR() {
2+
generateQRCodeForAsset(g_sysId);//get the sysid of selected record
3+
}
4+
5+
function generateQRCodeForAsset(sys_id) {
6+
var ga = new GlideAjax('GenerateAssetQR');//Script Include which stores data to be presented when QR-Code is Scanned
7+
ga.addParam('sysparm_name', 'getAssetQRData');
8+
ga.addParam('sysparm_sys_id', sys_id);
9+
10+
ga.getXMLAnswer(function(response) {
11+
var qrData = response;
12+
var qrURL = 'https://qrickit.com/api/qr.php?d=' + encodeURIComponent(qrData) + '&addtext=Get Asset Data';
13+
//QrIckit is a tool using which Customized QR-Codes can be generated
14+
var modalHTML = `
15+
<div style="text-align:center">
16+
<img id="qrCodeImage" src="${qrURL}" alt="QR Code" style="margin-bottom:10px;" />
17+
<p>Scan to view asset details</p>
18+
</div>
19+
`;
20+
21+
var gModal = new GlideModal("QR Code");
22+
gModal.setTitle('Asset QR Code');
23+
gModal.setWidth(500);
24+
gModal.renderWithContent(modalHTML);
25+
});
26+
}

0 commit comments

Comments
 (0)