|
| 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 | +``` |
0 commit comments