The CreatorCon Call for Content is officially open! Get started here.

CMP Pool Filter function sn_cmp_api.ExpressionResolverUtilScript().getMetadataRelations()

Sami Koskivaara
Giga Contributor

Quite often in CMP you will call this function

res = new sn_cmp_api.ExpressionResolverUtilScript().getMetadataRelations(
  sys_id,
  'Contains',
  tableName,
  'flat',
  1,
  param
);

It returns JSON string from the relationships that is suitable in the catalog items. How ever I haven't seen any documentation what does the `flat` and `1` parameters do. Can someone explain what are the extra parameters? Can you find the source code of this class and methods?

1 ACCEPTED SOLUTION

Ganesh Bhat
ServiceNow Employee
ServiceNow Employee

Internally to evaluate all the expressions of cloud management, expression util is used.

Expression documentation is here

https://docs.servicenow.com/bundle/orlando-it-operations-management/page/product/cloud-management-v2/reference/expressions-cloud-mgt.html

 

Let me explain the specific method signature and possible values here

getMetadataRelations(sys_id, metadataRelation, targetCIType, loadType, level, param );

This method helps you to flaten the relationship and gets the value in key-value pair needed for your filter. 

Given a top level sysId like Location, ServiceAccount, CloudAccount sysId, you can get the related child members. This method works on cmdb_rel_ci, instead of you explicitely querying the table with join, this helper method simplifies the overall code.

  • sys_id = sysId of current record which is either parent or child in cmdb_rel_ci table
  • metadataRelation = relationship in cmdb_rel_ci table
  • targetCIType = type of child or parent you are looking for ( they change based on if you ask for HostedOn:Hosts or reverse ) - typical values Hosts, Contains, else whatever is passed
  • loadType , levels =doesnt matter what you pass, its deprecated.
  • parms - keyAttributes and valueAttributes - values to extract from found entity.

 

View solution in original post

3 REPLIES 3

jain2
Tera Contributor

Hi Sami Koskivaara,

 

'Flat' and '1' means Level 1 Relationship from table.

 

Sami Koskivaara
Giga Contributor

What other options are there for `flat`? Where is this documented? How `flat` is different from `1` level relationship parameter?

Ganesh Bhat
ServiceNow Employee
ServiceNow Employee

Internally to evaluate all the expressions of cloud management, expression util is used.

Expression documentation is here

https://docs.servicenow.com/bundle/orlando-it-operations-management/page/product/cloud-management-v2/reference/expressions-cloud-mgt.html

 

Let me explain the specific method signature and possible values here

getMetadataRelations(sys_id, metadataRelation, targetCIType, loadType, level, param );

This method helps you to flaten the relationship and gets the value in key-value pair needed for your filter. 

Given a top level sysId like Location, ServiceAccount, CloudAccount sysId, you can get the related child members. This method works on cmdb_rel_ci, instead of you explicitely querying the table with join, this helper method simplifies the overall code.

  • sys_id = sysId of current record which is either parent or child in cmdb_rel_ci table
  • metadataRelation = relationship in cmdb_rel_ci table
  • targetCIType = type of child or parent you are looking for ( they change based on if you ask for HostedOn:Hosts or reverse ) - typical values Hosts, Contains, else whatever is passed
  • loadType , levels =doesnt matter what you pass, its deprecated.
  • parms - keyAttributes and valueAttributes - values to extract from found entity.