ServiceNow Metrics relationship between sc_task and metric_instance

Scott29
Kilo Sage

I created new metric definitions for the sc_task table. I have never created a relationship between tables before. How can I make a 1-to-many relationship between sc_task and metric_instance? Only the metrics that relate to that task and the task ID are in the metric

 

Scott29_0-1741106865106.png

 

I want to be able to show the related metrics on a relationship tab on the bottom of the task form. 

 

2 ACCEPTED SOLUTIONS

Rohit  Singh
Mega Sage

Hi @Scott29 ,

 

To create a related list showing all metrics related to the sc_task record you can do the following.

 

  1. Create a new Custom Relationship. System Definition->Relationships (Table Name: sys_relationship)
  2. Applies to -> sc_task (since you want to show related list on SC Task form)
  3. Query from -> Metric Table
  4. Use script section to build you query. 

 

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);

	current.addQuery("id",parent.sys_id);

})(current, parent);

 

  • Now in the SC Task from view use "configure related list" and bring you Custom Relationship in the from using slush bucket.

Refer an example in Incident Form:

 

RohitSingh_0-1741108494301.png

 

RohitSingh_1-1741108535831.png

 

 

 

If my response helped, please mark it helpful and accept the solution so that it benefits future readers.

 

Regards,
Rohit

View solution in original post

Chaitanya ILCR
Kilo Patron

Hi @Scott29 ,

if you have created a metric definition for SC task table

you should be able to see Metrics (just configure the related lists and add metrics)

ChaitanyaILCR_0-1741108799433.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Scott29 

 

Metrics are used to track the previous state or assignment group of a record. I'm not sure what your exact requirement is regarding the 1-to-M relationship."

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Rohit  Singh
Mega Sage

Hi @Scott29 ,

 

To create a related list showing all metrics related to the sc_task record you can do the following.

 

  1. Create a new Custom Relationship. System Definition->Relationships (Table Name: sys_relationship)
  2. Applies to -> sc_task (since you want to show related list on SC Task form)
  3. Query from -> Metric Table
  4. Use script section to build you query. 

 

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);

	current.addQuery("id",parent.sys_id);

})(current, parent);

 

  • Now in the SC Task from view use "configure related list" and bring you Custom Relationship in the from using slush bucket.

Refer an example in Incident Form:

 

RohitSingh_0-1741108494301.png

 

RohitSingh_1-1741108535831.png

 

 

 

If my response helped, please mark it helpful and accept the solution so that it benefits future readers.

 

Regards,
Rohit

Chaitanya ILCR
Kilo Patron

Hi @Scott29 ,

if you have created a metric definition for SC task table

you should be able to see Metrics (just configure the related lists and add metrics)

ChaitanyaILCR_0-1741108799433.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Thanks, you are correct. I checked for the relationship before I built the metric.