PARSE INFO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 07:57 PM - edited ‎10-05-2023 02:18 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2023 06:22 AM
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.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 08:49 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2023 09:22 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 01:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2023 01:43 PM