- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 09:44 AM
Hello experts,
Is there any way to extract a specific string from a line.
Format
"Teams Group with id '($NewGroup.Id)' updated with member settings allowCreateUpdateChannels:false and allowDeleteChannels:false"
example
'Teams Group with id '6667f10bcf2-1f71-48fd-8f04-5267787878787787' updated with member settings allowCreateUpdateChannels:false and allowDeleteChannels:false'
i need to get 6667f10bcf2-1f71-48fd-8f04-5267787878787787
rest of the format will always be the same
is there any way we can fetch it. I am new to servicenow scripting.
Thanx in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 10:33 AM
Hi @deepika46 try this code and modify accordingly
var gr = new GlideRecord('table_name');
gr.addQuery('sys_id', 'sys_id');
gr.query();
if (gr.next()) {
var inputString = gr.your_field_name;
var regex = /id '([^']+)'/;
var match = regex.exec(inputString);
if (match && match[1]) {
var groupId = match[1];
gs.info("Extracted ID: " + groupId);
} else {
gs.info("No ID found");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 10:33 AM
Hi @deepika46 try this code and modify accordingly
var gr = new GlideRecord('table_name');
gr.addQuery('sys_id', 'sys_id');
gr.query();
if (gr.next()) {
var inputString = gr.your_field_name;
var regex = /id '([^']+)'/;
var match = regex.exec(inputString);
if (match && match[1]) {
var groupId = match[1];
gs.info("Extracted ID: " + groupId);
} else {
gs.info("No ID found");
}
}