PARSE INFO

Dallas2
Tera Expert

Hello can anyone assist on script, trying to parse MSSQL15.MSSQLSERVER to be Put in table cmdb_ci_db_mssql_instance on instance_name field. this is coming from running process key parameters (running_process_key_parameters) field. I will be using a business rule, but the string below will not always be the same, the running process key parameters field will have different data, so will need to call the running process key parameters, parse and in put in the instance name field.. 

 

from this "E:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Binn\sqlservr.exe"-sMSSQLSERVER  

 

Thank you

 

 

 

 

16 REPLIES 16

Hi @Dallas2 

 

No it will not work.

In this case you can use the regular expression logic provided by @Amit Gujarathi 

To check the MSSQL name...!! & if matches then update it.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Amit Gujarathi
Giga Sage
Giga Sage

HI @Dallas2 ,
I trust you are doing great.

To parse the string "E:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Binn\sqlservr.exe"-sMSSQLSERVER and extract the instance name "MSSQL15.MSSQLSERVER", you can use a regular expression.

Here's a script that you can use to achieve this:

// Sample input string
var inputString = "E:\\Program Files\\Microsoft SQL Server\\MSSQL15.MSSQLSERVER\\MSSQL\\Binn\\sqlservr.exe\"-sMSSQLSERVER";

// Regular expression to match the instance name pattern
var regex = /MSSQL\d+\.\w+/;

// Extract the instance name using the regex
var instanceName = inputString.match(regex);

if (instanceName && instanceName[0]) {
    // If a match is found, update the 'instance_name' field in the 'cmdb_ci_db_mssql_instance' table
    var gr = new GlideRecord('cmdb_ci_db_mssql_instance');
    gr.initialize();
    gr.instance_name = instanceName[0];
    gr.insert();
    gs.info('Instance name ' + instanceName[0] + ' has been added to the table.');
} else {
    gs.warn('No instance name found in the input string.');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



But Iam getting it from the running process key parameter field, from the CMDB Ci db mssql instance table. Will that work, what you put 

from the attachment, it seems the script you wrote does not call the running process key parameters. iam trying to use a buisness rule, to parse from the running process key parameters, and put in the instance_name...

 

 

and use the business rule.... can you provide more insight