QR Code Generator in ServiceNow Using API Call - Article
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2025 10:28 PM - edited ‎01-01-2025 10:35 PM
QR Code Generator in ServiceNow Using API Call
Prerequisites
- A ServiceNow instance with appropriate permissions.
- Basic understanding of REST APIs.
- Knowledge of UI Actions and scripting in ServiceNow.
- API Endpoint: Quick Chart.
Steps to Implement
Step 1: Create a UI Action
Purpose: To trigger the QR code generation.
Configuration:
- Form Button: True
- Table: Change Request
- Client: True
- Action Name: generate_qr
Script:
function generate() {
gsftSubmit(null, g_form.getFormElement(), "generate_qr");
}
if (typeof window == "undefined")
qrCode();
function qrCode() {
var recordSysId = current.sys_id.toString();
var fieldValuePairs =
"NUMBER: " + current.number + "\n" +
"REQUESTED BY: " + current.requested_by.getDisplayValue() + "\n" +
"SHORT DESCRIPTION: " + current.short_description + "\n" +
"PRIORITY: " + current.priority + "\n";
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("get");
restMessage.setEndpoint("https://quickchart.io/qr");
restMessage.setQueryParameter("text", fieldValuePairs);
restMessage.setQueryParameter("centerImageUrl", "https://raw.githubusercontent.com/20481A0453/Kapimage/refs/heads/main/Blue%20Cap-feather.png");
restMessage.setQueryParameter("dark", "000000");
restMessage.setQueryParameter("light", "ffffff");
restMessage.setQueryParameter("centerImageSizeRatio", "0.50");
restMessage.saveResponseBodyAsAttachment("change_request", recordSysId, "QRCode.png");
restMessage.execute();
var response = restMessage.response.getBody();
gs.log("QR Code Response: " + response);
action.setRedirectURL(current);
}
Step 2: Test the Implementation
- Open a record in the Change Request table.
- Click the "Generate QR" button.
- Verify that the QR code is attached to the record as a file.
API Details
Endpoint:
Query Parameters:
- text: Contains the field-value pairs.
- dark: Hex code for the dark color.
- light: Hex code for the light color.
- centerImageUrl: URL of the image to be placed on the QR (for branding purposes).
- centerImageSizeRatio: A value between 0 and 1 to determine the image size ratio.
Demo Video
Check here.
Mark this as help full if this helps you to understand. if you have any questions, please feel free to reach out to me.
Happy Learning
Regards
Rathan Guntuka
#API #Integration
- 2,936 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 10:50 PM
I am using same code but no response on form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2025 05:17 AM
Same me too did not getting response on form .if you got the response please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2025 01:52 AM
Let me know if you are still facing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2025 12:09 AM