String field that auto populate with Barcode

Alon Grod
Tera Expert

Hi,

I need to create a field of type String on the incident table that will be read only.

After the user create an incident, this field needs to be auto populate with the sys id of the incident but it should be a barcode that can be scanned. the scanning will return the sys id of the incident

1 ACCEPTED SOLUTION
5 REPLIES 5

Ankur Bawiskar
Tera Patron

@Alon Grod 

there is no direct way available for this

How to Generate and Embed a QR Code in a Document Template in ServiceNow 

there is also a paid store app for this

Barcode & QR Code Generator 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Tom8901
Giga Contributor

This can usually be handled with a Business Rule that runs after insert. The rule can copy the record’s sys_id into a read-only string field and then use a barcode font or barcode image generator to display it in scannable form.

nayanmule
Kilo Sage

@Alon Grod  , I don't think if that is possible to do. This functionality is usually used in Mobile Agent apps to scan and populate the fields.

 

Regards,

Nayan

Aswin S
Tera Contributor

Hi,

Yes, this is completely possible in ServiceNow. Below is a simple and supported step-by-step approach.


Step 1: Create a read-only field

  • Table: incident

  • Field type: String

  • Field name: u_incident_barcode

  • Length: 32

  • Mark the field as Read-only

This field will store the Incident sys_id.


Step 2: Auto-populate the field after Incident creation

Create an After Insert Business Rule on the Incident table.

(function executeRule(current, previous) {
    if (!current.u_incident_barcode) {
        current.u_incident_barcode = current.sys_id;
        current.update();
    }
})(current, previous);

This ensures the field is populated only once, immediately after the record is created.


Step 3: Render the value as a barcode

Create a UI Macro to display the stored sys_id as a Code-128 barcode.

<jelly>
  <img src="https://bwipjs-api.metafloor.com/?bcid=code128&text=${current.u_incident_barcode}&scale=3&height=10" />
</jelly>

Code-128 is recommended because it supports alphanumeric values and works with most barcode scanners.


Step 4: Display it on the Incident form

  • Create a UI Formatter referencing the UI Macro

  • Add the formatter to the Incident form layout


Result

  • Incident is created

  • The read-only field is populated with the Incident sys_id

  • A scannable barcode is displayed on the form

  • Scanning the barcode returns the sys_id

This approach follows best practices on the ServiceNow platform.

Hope this helps.

 

Regards,

Aswin