Want to show parent as well as RITM child number in requested item related list tab.

Nikita9
Mega Expert

Hi All,

We have a requirement where i need to show RITM's parent as well child of that particular RITM in requested item related list on RITM form.

find_real_file.png

 

Pls help.

1 ACCEPTED SOLUTION

Hi Nikita,

So here you go

My Example has this:

RITM0010028 is parent of RITM0010029

RITM0010029 is parent of RITM0010027

RITM0010029 is parent of RITM0010026

find_real_file.png

1) Create defined relationship from left navigation -> Relationships -> System Definition

Name - Related RITMs

a) Applies to table -  sc_req_item

b) Queries from table - sc_req_item

Script:

(function refineQuery(current, parent) {

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

	var ritmSysId = parent.parent;
	var currentSysId = parent.sys_id;
	// get the childs
	var arr = [];
	var gr = new GlideRecord("sc_req_item");
	gr.addQuery("parent","IN", currentSysId);
	gr.query();
	while(gr.next()) {
		arr.push(gr.getValue('sys_id'));
	}

	current.addQuery("sys_id", "IN", arr.toString()).addOrCondition("sys_id", parent.parent);

})(current, parent);

find_real_file.png

Then add it on the related list by Configure -> Related Lists

Output: RITM0010029 related list will show it's child RITM0010027 and RITM0010026 and also it's parent RITM0010028

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

20 REPLIES 20

Hi,

You will have to create custom defined relationship for this

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Nikita,

So here you go

My Example has this:

RITM0010028 is parent of RITM0010029

RITM0010029 is parent of RITM0010027

RITM0010029 is parent of RITM0010026

find_real_file.png

1) Create defined relationship from left navigation -> Relationships -> System Definition

Name - Related RITMs

a) Applies to table -  sc_req_item

b) Queries from table - sc_req_item

Script:

(function refineQuery(current, parent) {

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

	var ritmSysId = parent.parent;
	var currentSysId = parent.sys_id;
	// get the childs
	var arr = [];
	var gr = new GlideRecord("sc_req_item");
	gr.addQuery("parent","IN", currentSysId);
	gr.query();
	while(gr.next()) {
		arr.push(gr.getValue('sys_id'));
	}

	current.addQuery("sys_id", "IN", arr.toString()).addOrCondition("sys_id", parent.parent);

})(current, parent);

find_real_file.png

Then add it on the related list by Configure -> Related Lists

Output: RITM0010029 related list will show it's child RITM0010027 and RITM0010026 and also it's parent RITM0010028

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

hi Ankur,

Thank you very much for this helpful content. But my question is Can't i do the same setup in requested item related list?

 

Regards,

Nikita

Hi,

Glad that it helped.

The OOB related list just shows the child RITMs of the Current RITM

It won't show the Parent of the current RITM

You will have to go with the approach I shared

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

hi Ankur,

Is there any way to show filter like 'parent=RITM0010028 or parent.parent=RITM0010029' in breadcrumb in the Related Items related tab?