Assign tag through Business rule

chidanandadhath
Kilo Guru

I want to add tag 'Data Error' in cmdb_ci form through business rule...is it possible?

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Change the sys_id of the label as per your need.

 

var addLabelGR = new GlideRecord('label_entry');
addLabelGR.initialize();
addLabelGR.label = '4336c042dbd6485046a579a58c9619dd'; //change the sys id of the label you want.
addLabelGR.table = 'tablename';
addLabelGR.table_key = 'sys ID of record';
addLabelGR.insert();

 

You can get the sys id of the label from label table.

View solution in original post

8 REPLIES 8

You can achieve this with the use of below piece of code in the Business rule script. Check the advanced checkbox and use the script in Advanced section.

gs.addInfoMessage("type the text message here");

kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Chaitanya

Kalaiarasan Pus
Giga Sage

Change the sys_id of the label as per your need.

 

var addLabelGR = new GlideRecord('label_entry');
addLabelGR.initialize();
addLabelGR.label = '4336c042dbd6485046a579a58c9619dd'; //change the sys id of the label you want.
addLabelGR.table = 'tablename';
addLabelGR.table_key = 'sys ID of record';
addLabelGR.insert();

 

You can get the sys id of the label from label table.

Hello Kalaiarasan,

How can we update the tag to multiple records on condition basis. suppose i want to update tag automatically if assignment group is something. Thank you

 


@Kumar147 wrote:

Hello Kalaiarasan,

How can we update the tag to multiple records on condition basis. suppose i want to update tag automatically if assignment group is something. Thank you


To accomplish this, you would only need to build your GlideRecord query first, then iterate through each record and use Kalaiarasan's example above in the body of your while loop. For example, if you wanted to tag every active Incident record for a particular assignment group with a certain tag, you could do:

var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('assignment_group', 'sys id of the assignment group');
incidentGR.addActiveQuery();
incidentGR.query();

while(incidentGR.next()) {
  var addLabelGR = new GlideRecord('label_entry');
  addLabelGR.initialize();
  addLabelGR.label = 'sys id of the label you want.';
  addLabelGR.table = 'incident';
  addLabelGR.table_key = incidentGR.sys_id;
  addLabelGR.insert();
}