logo

NJP

How to perform Asset Audits by Asset Tag and/or Serial Number

Import · Sep 10, 2021 · article

Here’s the dilemma, you are the Asset Manager for an organization that either now or at one time didn’t have complete Asset Tag coverage across all your trackable hardware assets. This leaves you needing to scan assets utilizing the manufacturer’s Serial Number bar code to perform an Asset Audit in ServiceNow’s Hardware Asset Management (HAM) product. You might even need the option to scan either an Asset Tag or a Serial Number but off the shelf, HAM’s mobile support only allows for scanning by Asset Tag as seen in the image below where I’m scanning from a sheet of barcodes. You would, of course, scan the Asset Tag on the hardware asset.

Asset Tag scan input

image

Asset Tag scan result

image

What is the solution?

The solution is to modify the System Mobile function that both presents the Asset Tag attribute within the Mobile Agent application and processes the scanned inputs within the ServiceNow instance. You can find it here: System Mobile -> Functions -> Asset Scan.

image

Three Steps to Success

Before we start making changes, it is important to note that this is a customization. As such, it may not be supported by ServiceNow Tech Support. Be sure to test your changes thoroughly before deploying them into a Production Instance.

There are three steps (other than testing) to configure the Asset Scan Function to accept either Serial Numbers or Asset Tags as inputs. Be sure to commit the changes to a Hardware Asset Management scoped Update Set so you can move the configuration up your ServiceNow instance stack. I’ve attached an Update Set created in Quebec Patch 4 Hotfix 2b and tested in Rome EA to this blog. Using it might work just fine for you, but I’d encourage you to read on to understand exactly what the Update Set changes in your system. You may also want to configure the system yourself, to be sure there aren’t any issues should your instance not be on Quebec Patch 4 Hotfix 2b or Rome EA.

Step 1: Add Serial Numbers as a Grouped Input.

In this step, you’ll add a Grouped Input record to the Asset Scan Function I referenced above. Here are the values you’ll use to set it up correctly once you click on the Grouped Inputs “New” button. When you are done, Serial Numbers will appear along with Asset Tags in the Mobile UI.

image

Step 2: Change the “Mandatory” setting on the asset_tags Grouped Input

This is an important step so you can choose either Serial Numbers or Asset Tags as inputs. You can even get crazy and choose both. However, without removing “mandatory” from the asset_tags Grouped input, the Mobile UI will raise an error when you attempt to submit your scanned Serial Number bar codes without including any Asset Tags.

To make the change, you can either open the record and change the attribute or you can do it right from the list view in the Grouped Inputs tab as shown below. Be sure to click the green Save checkmark or the Enter key on your computer to save the change.

image

Here we see both inputs in the Mobile Agent.

image

Step 3: Modify the Audit Scan Action Item to account for Serial Number inputs.

Near the top of the Asset Scan Function record we’ve been working in there is a reference field with Action Item as the label. You’ll find the reference field populated with “Audit Scan”, which is the Action item used to process the scanned inputs from the Mobile Agent. In this step you’ll need to either update the out of box Audit Scan action item or copy it and modify the copy. There are arguments for both approaches. In my example we’ll copy the original Audit Scan action item record and use that copy going forward.

Start by opening the Audit Scan Action item. Then modify the Name attribute to your liking. I’ve chosen “Audit Scan with Serial Numbers”. Once you’ve altered the Name attribute choose “Insert and Stay” from the right-click menu in the gray header bar. You can also find “Insert and Stay” via the “hamburger” button at the top left of the window.

image

Now that you’ve copied the original processing action item you can modify the Execution Script to account for Serial Number inputs. I’ve attached the new Execution Script to this Blog entry for easy use. You can simply open the attached file, then cut and paste its contents over the entirety of the Execution Script in the form. However, if you’d like to be more hands-on, you’ll need to make the code updates as I describe below. Use the file I’ve provided as a comparison to help you make the necessary changes.

Note: Code line numbers referenced below are from the Quebec Patch 4 Hotfix 2b release. If you attempt to make the identified changes on your own, be careful to find the correct lines on which to commit updates.

The new Execution Script leverages the out-of-box script. The out-of-box script is broken into three main sections: Lines 1- 57 declare the WriteBackAction function and then populate tables used to compute the final scan results shown in the UI. Lines 59 – 167 process Asset Tag inputs. Lastly, lines 169 – 210 compute the final scan result numbers returned to the UI.

Copy the out-of-box portion of script that processes Asset Tags (lines 59-167) then insert it as a new section for the processing of Serial Numbers. Insert it below the original (at line 168) and above the final number computing section giving the new script four major sections of code. The new Serial Number computing section is modified substituting Serial Number references in the place of Asset Tag references and appending “SN” to each of the declared variables and uses of those variables within the code.

The Asset Tag processing section and the Serial Number processing section are then placed into “if” statements which preclude processing if either no Asset Tags or no Serial Numbers are submitted from the Mobile Agent. Be sure to provide an open bracket and a close bracket around each section. Because asset_tags and serial_numbers (the names of the Grouped inputs we modified in Step 2) are arrays, we can test to see if the array object is undefined. Undefined means no data for that object was sent for processing by the Mobile Agent. Code examples are below:

if (input.asset_tags != undefined) { do the work defined in the asset tag processing section }

if (input.serial_numbers != undefined) { do the work defined in the serial number processing section}

View original source

https://www.servicenow.com/community/sam-blog/how-to-perform-asset-audits-by-asset-tag-and-or-serial-number/ba-p/2283735