Wild Card for TAG field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 08:50 AM
Hi Engineers,
My business users are using TAG field on computer(cmdb_ci_computer) record to label a record for any Project.
Like PROJ-Exchange, PROJ-BlueInk, PROJ-SailView etc where the prefix is fix as "PROJ-"
My requirement is to create an incident for all such tagged records.
I am able to create an incident in multiple ways (Business Rule, Flow Designer, Scheduled Job).
But my struggle is, I have to provide exact TAG value. Is there a way I can use wild character like "STARTS WITH" or "CONTACINS" for TAG field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 09:33 AM
Sure can. For example, I added a Hello world tag to a Catalog Task:
And you can do a query like:
var label_entry = new GlideRecord('label_entry');
//label.nameLIKEhello
label_entry.addEncodedQuery('label.nameLIKEhello');
label_entry.query();
while(label_entry.next()){
//create incident
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 09:55 AM
Thanks @Kris Moncada . My current code is triggering from CMDB_CI_COMPUTER table. However I evaluated the option of using label_entry as source where wild card are allowed, but was finding difficulty in gliding to computer record to add computer attributes to the incident. The target field which hold computer record sys_id, is a string field not referenced one. If there is no Stright forward option, I will evaluate using string functions to extract sys_id use that to glide record computer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 07:09 PM - edited 06-06-2024 07:11 PM
This will create an incident for every cmdb_ci_computer that is tagged with "PROJ-". The incident will also have the configuration item associated.
var label_entry = new GlideRecord('label_entry');
label_entry.addEncodedQuery('label.nameSTARTSWITHPROJ-^table=cmdb_ci_computer');
label_entry.query();
while (label_entry.next()) {
var table = label_entry.getValue('table');
var gr = new GlideRecord(table);
if (gr.get(label_entry.getValue('table_key'))) {
var incident = new GlideRecord('incident');
incident.initialize();
incident.setValue('short_description', label_entry.getValue('title'));
incident.setValue('caller_id', gs.getUserID());
incident.setValue('cmdb_ci', label_entry.getValue('table_key'));
incident.insert();
}
}