Parse a Serial Number from a String

Nate10
Kilo Contributor

SCCM creates a serial number value for a CMDB CI that has the following format:


/12BDMQ2/CNCMK0089P011E/

It needs to be:

12BDMQ2

Using a business rule, can someone suggest a method to replace the first value with the extracted test between the  first and second '/'  ? 

 

(function executeRule(current, previous /*null when async*/) {

// Select out the string between the first two slash characters and discard the rest.

// read in the value of cmdb_ci_computer.serial serial number
var u_sccm_computer_sn = user.getValue("lob").split(',');

})(current, previous);

Thanks for any suggestions. 

 

 

 

1 ACCEPTED SOLUTION

HarshTimes
Tera Guru

YOu can try

var str =  "/12BDMQ2/CNCMK0089P011E/" ;

str.split("/");

var serial_number = str[1] ;

 

 

-Harsh

View solution in original post

8 REPLIES 8

Nate10
Kilo Contributor

After evaluating the problem more carefully, it was decided that a better approach would be to modify the Discovery Pattern or Probe to solve the issue rather than using a script.  The script does work but it's not the best solution. Thank you for the responses. 

Nate10
Kilo Contributor

Brent and Harshtimes both had correct answers to the original post. Harshtimes code was a bit more elegant so I have to go with his response. 

I liked Harshtimes clever use of split to create an array too. A simple and elegant way to extract the required data.

Nate10
Kilo Contributor

I wrote up the fix in a document, here's an updated version of it. 

In the case of some Dell computers, the Serial Number populating the Serial Number attribute for of a Computer CI Base class contains the following format:

/JZ0BYV1/CN7016326P0H2C/

The “/” characters and the extraneous string that follows the 7 character serial number is causing the CI to improperly coalesce with the Asset Spreadsheet data import. This is resulting in duplicates and incorrect information. The format above is retrieved directly from Win32_BaseBoard via a WMI query of Windows Operating systems running on a Dell personal Computers. The Windows - Hardware probe and the pattern Windows - Hardware Information.  retrieved the value for the Baseboard Chassis.

The following procedures provide a method to block this attribute from populating with the Baseboard Chassis. There are several other alternate sources that may be used for the Serial Number including BIOS and a different WMI query. The absence of the Baseboard Serial Number will result in one of the alternate Serial Numbers populating.

Once the correction is implemented, the serial number will self-correct on the next discovery cycle.

There are two methods for executing Discovery in Kingston: By Probes and By Patterns. In the case of [customer], we are using Patterns. The following provides procedures for adjusting the Discovery for both methods.

Discovery Patterns Method - Stopping the probe from retrieving or recognizing Baseboard Chassis

Locate the Discovery Pattern Windows Identity - Hardware Information and modify it to block discovery of the Baseboard Chassis Serial Number.

  1. Navigate to Pattern Designer --> Discovery Patterns.
  2. Filter on Name “Windows Identity - Hardware”
  3. Open the Pattern and select the Pattern tab
  4. Locate and remove the following Code:

    step {
    name = "Serial number from Win32_BaseBoard"
    comment = "Serial number from Win32_BaseBoard"
    run_wmi_query_to_var {
    namespace = "root\\CIMV2"
    query = "SELECT SerialNumber FROM Win32_BaseBoard"
    var_names = table {
    name = "Win32_BaseBoard"
    }
    if_not_found_do = nop {}
    cache_flag = 0
    }  
    }

  5. After removing the code, Save the pattern
  6. Select Synchronize with MID Servers.