Wild Card for TAG field

Bikash R Swain
Tera Contributor

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?

3 REPLIES 3

Kris Moncada
Tera Guru

Sure can. For example, I added a Hello world  tag to a Catalog Task:

KrisMoncada_0-1717691556102.png

 

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.

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.

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();
  }
}