Making tags mandatory?

danielbilling
Kilo Guru

Hi,

is there a way to make Tags mandatory?

would like to force user to select at least 1 tag before closure

/Daniel

2 REPLIES 2

Michael Ritchie
ServiceNow Employee

You can but it is tricky since tags (aka labels) are stored in a separate table and linked to tasks.   Tags used to be called Labels and the Tag names themselves are stored in a table called "label".   Then there is a record called Label Entry that links a tag to a record.   So you could create a business rule that runs when the state is closed to query this label_entry table to see if there is a record and if not prevent save.



Example Business Rule that worked in a quick test when changing state to In Progress:


find_real_file.png



Then on the advanced tab use the following script:


(function executeRule(current, previous /*null when async*/) {



      var labelEntry = new GlideRecord("label_entry");


      labelEntry.addQuery("table", current.sys_class_name);


      labelEntry.addQuery("table_key", current.sys_id);


      labelEntry.query();


      if (!labelEntry.hasNext()) {


              current.setAbortAction(true);


              gs.addErrorMessage("You must select at least one Tag.");


      }



})(current, previous);


Great, that's a straight forward solution.



i was also trying to find out if it would be possible to reuse the macro from editing tag in list view... as has more functionality.