Adding Capture Patterns to ServiceNow

Some barcodes have more information than the actual value. Like starting a serial number barcode with an S. The S is used to tell the scanner this is a serial number, but is not part of the serial number itself. For example, a barcode of S12345 may mean an actual serial number of 12345.

AssetTrack can be configured to parse a scanned value and use a portion of it to perform a query.

To do this, you need to teach AssetTrack how to recognize if it should parse a scanned value before doing a lookup. Do this by adding a global scan capture pattern to AssetTrack.

Configure a Global Capture Pattern

Required version: v2.09 with update set 2.0.9.2 Core and Admin

A global pattern applies to all key fields (Asset Tag, Serial Number, Mac Address) when scanning assets into bulk forms. When you set a global scan pattern, any value you scan into AssetTrack will be checked against this pattern. If it matches, then only the portion of the matched pattern specified in the output will be processed.

Apply the pattern to the global.defaults record in AMI Application Data. Drop the scan capture pattern into the value to apply the global scan pattern for all forms. Supports both Bulk and Single forms. 

2018-08-24_16-04-52.png

Stripping the leading S example

The example global pattern below strips the leading S from each scan.

{
 "scanCapture":  [{
"regex": "[Ss]([a-zA-Z][a-zA-Z0-9]*)",
"output": "$1"
}]
}
 

Configure a Capture Pattern on a Single-Asset Form Field

Required version: v2.08 - Single Form only support

You can attach a scan pattern to a specific field on Single Asset forms, such as the serial number.

Find the applicable field in the AMI Entity Field table (x_amiam_assettrack_ami_entity_field). For serial number, the record is Entity: Asset, Field: serial_number.

Add a new node into the "scan" property to the Field JSON, sibling to "behavior" and "queries" called "capture" (n.b. any RegEx backslash syntax must be escaped by adding an additional backslash e.g. \d => \\d)

"scan": { 
"behavior": ...,
"queries": [...],
"capture": [{ 
"regex": "[Ss](\\S{12})", 
"output": "$1" 
}]

In this example, strip the first S or s when finding barcodes starting with an S or s and followed by 12 characters, strip the S|s.

Return multiple sections of the scanned value by adding multiple capture sections ()

"scan": {
	"behavior": ...,
	"queries": [...],
	"capture": [{
		"regex": "AA(\\d+)BB(\\d+)AA.*",
		"output": "$1$2"
	}]
}

In this example a scanned value of AA55BB239AA999 would have "55" ($1) and "239" ($2) captured within the (\\d+) capture groups and the output would therefore be "55239".

Multiple capture regex can be specified to match different patterns encountered, they are resolved in order until one matches. If none match the raw scanned value is used.

Not specifying an output format will cause the client to use the full raw value, this can be useful when a sub-pattern should be handled differently than a more general pattern, e.g.:

"scan": {
	"behavior": ...,
	"queries": [...],
	"capture": [{
		"regex": "U\\d+"
	},{
		"regex": "[A-Z](\\d+)",
		"output": "$1"
	}]
}

In this case all single letter prefixed values would be stripped off, e.g. V532955 => 532955, except when the scanned value was prefixed with a U. e.g. U23557 => U23557.

Have more questions? Submit a request

Comments

  • Avatar
    Rick Goodlaski

    "capture": [{
    "regex": "[Ss](\\S{12})",
    "output": "$1"
    }]

    For barcodes starting with an S or s and followed by 12 characters, strip the S|s.

    Comment actions Permalink

Please sign in to leave a comment.