Want to create related list on the problem , where it contain 2 field value on from different table

jaiho_rai
Kilo Sage

HI 

There is requirement need to create related list on Problem 

 

Where Problem - Change Request (related list) and also problem have "Change request" (if add in the form) 

 

When you create from problem - hamburger - "Create standard Change" UI action that appears is --> -->"Change Request (Problem form have that field only it appear over there only)

Relationship /sys_m2m.list

current.addQuery('parent', parent.sys_id).addOrCondition('sys_id', rfc);
1 ACCEPTED SOLUTION

SasiChanthati
Giga Guru

Base on the scenario use case you have mentioned, I am assuming that you are trying to create a related list on the Problem form that shows Change Requests in two scenarios:

  1. Standard relationship: Change Requests that are directly related to the Problem via a field (e.g., problem_id on the Change Request table).

  2. M2M relationship: Change Requests linked via a many-to-many (M2M) relationship (like when using the "Create Standard Change" UI action).

Please try either:

  • Create a custom related list that shows both sets of Change Requests together.

  • Or create two separate related lists if merging is not possible.

Requirements:

  • Display Change Requests on Problem form via:

    • A direct field (one-to-many).

    • A many-to-many relationship (sys_m2m).

  • Triggered by "Create Standard Change" UI action, which sets the M2M.

Option 1: Use a Filtered Related List

If the Change Requests are all in the change_request table but related in different ways, you can create a filtered related list.

We need to:

  1. Create a Database View or use a custom GlideRecord query (if scripting).

  2. Use a Related List via the sys_relationship table (sys_relationship.list).

 

Setup in sys_relationship:

  1. Go to: System Definition > Relationships

  2. Create a new relationship:

    • Name: Change Requests from Problem

    • Applies to: problem

    • Related table: change_request

    • Query with script: check the box

Use this script:

(function executeRule(current, parent) {
var rfc = parent.u_change_request; // Field holding reference to single Change Request
var gr = new GlideRecord('change_request');
gr.addQuery('problem_id', parent.sys_id); // or whatever direct relationship field is
if (rfc) {
gr.addOrCondition('sys_id', rfc);
}

return gr;
})(current, parent);

 

This shows Change Requests where:

  • problem_id equals current problem

  • OR sys_id equals the value in a field (like u_change_request or change_request)

If we are using M2M Table

If "Create Standard Change" creates an M2M entry (e.g., change_request_problem), you can:

  1. Go to sys_m2m.list

  2. Find or create M2M:

    • Table: problem

    • M2M Table: e.g., change_request_problem

    • Ensure change_request is on that table and correctly mapped.

  3. Then, just add the M2M related list to the Problem form layout:

    • Form Layout → Related Lists tab → Add "Change Request Problem"

Method How

Direct Related ListUse problem_id on change_request
Custom Related ListUse sys_relationship with query script
M2M Related ListUse sys_m2m table like change_request_problem

 

 

View solution in original post

1 REPLY 1

SasiChanthati
Giga Guru

Base on the scenario use case you have mentioned, I am assuming that you are trying to create a related list on the Problem form that shows Change Requests in two scenarios:

  1. Standard relationship: Change Requests that are directly related to the Problem via a field (e.g., problem_id on the Change Request table).

  2. M2M relationship: Change Requests linked via a many-to-many (M2M) relationship (like when using the "Create Standard Change" UI action).

Please try either:

  • Create a custom related list that shows both sets of Change Requests together.

  • Or create two separate related lists if merging is not possible.

Requirements:

  • Display Change Requests on Problem form via:

    • A direct field (one-to-many).

    • A many-to-many relationship (sys_m2m).

  • Triggered by "Create Standard Change" UI action, which sets the M2M.

Option 1: Use a Filtered Related List

If the Change Requests are all in the change_request table but related in different ways, you can create a filtered related list.

We need to:

  1. Create a Database View or use a custom GlideRecord query (if scripting).

  2. Use a Related List via the sys_relationship table (sys_relationship.list).

 

Setup in sys_relationship:

  1. Go to: System Definition > Relationships

  2. Create a new relationship:

    • Name: Change Requests from Problem

    • Applies to: problem

    • Related table: change_request

    • Query with script: check the box

Use this script:

(function executeRule(current, parent) {
var rfc = parent.u_change_request; // Field holding reference to single Change Request
var gr = new GlideRecord('change_request');
gr.addQuery('problem_id', parent.sys_id); // or whatever direct relationship field is
if (rfc) {
gr.addOrCondition('sys_id', rfc);
}

return gr;
})(current, parent);

 

This shows Change Requests where:

  • problem_id equals current problem

  • OR sys_id equals the value in a field (like u_change_request or change_request)

If we are using M2M Table

If "Create Standard Change" creates an M2M entry (e.g., change_request_problem), you can:

  1. Go to sys_m2m.list

  2. Find or create M2M:

    • Table: problem

    • M2M Table: e.g., change_request_problem

    • Ensure change_request is on that table and correctly mapped.

  3. Then, just add the M2M related list to the Problem form layout:

    • Form Layout → Related Lists tab → Add "Change Request Problem"

Method How

Direct Related ListUse problem_id on change_request
Custom Related ListUse sys_relationship with query script
M2M Related ListUse sys_m2m table like change_request_problem