Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

How to to copy the tags and populate in the respective fields in the Server Class

MalathiP2130156
Tera Contributor

Hello Everyone,

 

The Infra team is managing tags for Cloud Hosted VM in Azure Portal and through SG-Azure, the tags are discovered either as a VM Instance or Cloud Resource. 


The requirement is tags are stored in cmdb_key_value table. How to copy those tags and to get that populated in the respective attributes in the Server class.

4 REPLIES 4

pavani_paluri
Kilo Sage

Hi @MalathiP2130156 ,

 

The Azure tags discovered through SG-Azure are stored in the cmdb_key_value table and, unfortunately, there is no out-of-the-box capability to automatically populate those values into fields on cmdb_ci_server.

What I've typically seen customers do is use a Business Rule, Flow, or Scheduled Job to read the required tags from cmdb_key_value and update the corresponding attributes on the Server CI.

 

For example:

Environment tag → u_environment
CostCenter tag → u_cost_center
Owner tag → u_owner


The process would be:

  • Identify the Server CI associated with the tag record.
  • Read the required tag values from cmdb_key_value.
  • Update the matching fields on cmdb_ci_server.
  • Trigger the update whenever a tag is added or changed.


If the tags change frequently, I'd recommend a Business Rule for near real-time updates. If the volume is large and changes are less frequent, a Scheduled Job may be a better option from a performance perspective.

Personally, I'd keep cmdb_key_value as the source of truth and sync only the required tags to CI attributes rather than duplicating all tag data.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P

 

Hi @pavani_paluri ,

 

Here in my customer, SGC-Azure is configured and the tags are populated for Cloud Resource CI and not for the Server CI. So, in this case not sure how to fetch the tags from the cmdb_key_value table and to populate in the respective Server class custom fields.

Hi @MalathiP2130156 ,

 

I have created a business rule which runs on Key value (cmdb_key_value) table and copies tags from VM Instance record to related Server record on inser and update. Hope it helps to achieve the use case for you.

______________________________________________________________________________

 var vmSysId = current.configuration_item.sys_id;

    if (current.operation() == 'insert') {

        var rel = new GlideRecord("cmdb_rel_ci");
        rel.addEncodedQuery("type=d93304fb0a0a0b78006081a72ef08444^child.sys_id=" + vmSysId);
        rel.query();
        if (rel.next()) {
            var newKey = new GlideRecord("cmdb_key_value");
            newKey.initialize();
            newKey.key = current.key;
            newKey.value = current.value;
            newKey.configuration_item = rel.parent.sys_id;
            newKey.insert();
            //  gs.info('Record inserted');
        }
    } else if (current.operation() == 'update') {

        var relRec = new GlideRecord("cmdb_rel_ci");
        relRec.addEncodedQuery("type=d93304fb0a0a0b78006081a72ef08444^child.sys_id=" + vmSysId);
        relRec.query();
        if (relRec.next()) {
            var servRecId = relRec.parent.sys_id;
            var updateKey = new GlideRecord("cmdb_key_value");
            updateKey.addEncodedQuery("configuration_item.sys_id=" + servRecId + "^key=" + current.key);
            updateKey.query();
            if (updateKey.next()) {
                updateKey.key = current.key;
                updateKey.value = current.value;
                updateKey.update();
            }
            // gs.info('Record updated');
        }


    }

svirkar420
Kilo Sage

Hi @MalathiP2130156 , For your requirement you will have to create a BR and update those values in respective attributes in the Server class from cmdb_key_value  table.

 

If this response helps you mark it as accepted solution and give it a thumbs up 👍. This help me and community to find answers quickly.

Best Regards,

Saurabh V.