Displaying custom attributes

The BMC Helix Discovery data model allows additional attributes to be added to nodes. You should only ever add additional attributes to inferred nodes. You must never update DDD nodes.

Attributes might be added by patterns at any point in time. It is strongly recommended that you add attributes at creation time when building your own inferred nodes. Inferred nodes that were created by the system must be modified using a separate pattern.

Once you have modified the node it is necessary to make the attribute visible. You can do this in the following ways:

  • Using model.addDisplayAttribute
  • Populating the _tw_meta_data_attrsattribute on the inferred node

To display the custom attribute on the node view using model.addDisplayAttribute

You can add the newly created attribute, or list of attributes, to those displayed on the node page using the model.addDisplayAttribute function. For example, to display the server_name attribute, use the following:

if si.server_name then
      model.addDisplayAttribute(si, "server_name");
end if;

Similarly, to display the attribute list list_attrs, use the following:

      list_attrs :=[]; // list of attribute names
      if si.port then
         list.append(list_attrs, "port");
      end if;
      if si.server_name then
         list.append(list_attrs, "server_name");
      end if;
   model.addDisplayAttribute(si, list_attrs); 

Note

If the attribute name contains some underscore ("_") characters, they will trigger a string format of the attribute when displayed. For example, the server_name attribute above will be displayed as "Server Name".

To remove the custom attribute from the node view

You can remove attributes that you have created, or a list of attributes that you have created, from those displayed on the node page using the model.removeDisplayAttribute function. For example, to remove the server_name attribute, use the following:

   model.removeDisplayAttribute(si, "server_name");

Similarly, to remove the attribute list list_attrs, use the following:

   model.removeDisplayAttribute(si, list_attrs);

Populating the _tw_meta_data_attrs attribute on the inferred node

If using this method, you must ensure only one pattern modifies the _tw_meta_data_attrs value on a particular node otherwise the conflicting changes are likely to result in the loss of one of the updates. Using the model.addDisplayAttribute and model.removeDisplayAttribute functions is simpler.

To add a custom attribute at node creation

Adding a custom attribute when a node is created is shown in the example below.

jrun_si := model.SoftwareInstance(key := key,
                                  name := name,
                                  type := type,
                                  version := full_version,
                                  product_version := product_version,
                                  build := build,
                                  server_id := server_id,
                                  _tw_meta_data_attrs := ['server_id']);

To add a custom attribute after node creation

You can also add a custom attribute to a node after it is created. This might be in the pattern that creates the node, or where you are adding an attribute to a system created node, in a separate pattern.

   if server_name then
      si_node._tw_meta_data_attrs := ['server_name'];
   end if;

To add a list of attributes

The following example code shows how to add a list of attributes to an existing node. The code creates a list, adds values, and assigns it at once.

      ltw_meta_data_attrs :=[]; // local list of attribute names
      if si.port then
         list.append(ltw_meta_data_attrs, "port");
      end if;
      if si.server_name then
         list.append(ltw_meta_data_attrs, "server_name");
      end if;
   si._tw_meta_data_attrs := ltw_meta_data_attrs; 
Was this page helpful? Yes No Submitting... Thank you

Comments