can we query script include function to the related list

suresh m2
Tera Contributor

Hi Team,

can we query script include function to the related list for M2M Relationship.

If yes could you please help me how to do that.

Thanks,

Suresh

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Can you elaborate on what you are trying to achieve?

Please add screenshots and table names and how they are related 

-Anurag

Revanth Karra
Tera Expert

Dear Suresh,

 

Hi @suresh m2 . Hope you're doing great! 

 

Yes, it is possible to query a script include function to the related list for an M2M relationship. To do this, you can use the following steps:

  1. Create a new script include function that returns the data that you want to display in the related list.
  2. In the script include function, use the GlideRecord object to query the data from the related table.
  3. Return the data from the GlideRecord object to the related list.

Function returns a list of all of the incidents that are related to the current change request:

 

function getRelatedIncidents() {
  var gr = new GlideRecord('incident');
  gr.addQuery('sys_id', 'IN', current.getRelationships('incident'));
  gr.query();

  var incidents = [];
  while (gr.next()) {
    incidents.push(gr);
  }

  return incidents;
}

 

 
Note:

To use this script include function in a related list, you would follow these steps:

  1. Go to the related list form.
  2. In the Related List Definition section, click New.
  3. In the Type field, select Scripted Relationship.
  4. In the Script Include field, enter the name of the script include function that you created in step 1.
  5. Click Save.

The related list will now display the data that is returned by the script include function.

You can also use script include functions to filter the data that is displayed in the related list.

 

Function returns a list of all of the incidents that are related to the current change request and that have a status of New:

 

 

function getRelatedIncidentsWithNewStatus() {
  var gr = new GlideRecord('incident');
  gr.addQuery('sys_id', 'IN', current.getRelationships('incident'));
  gr.addQuery('status', '=', 'New');
  gr.query();

  var incidents = [];
  while (gr.next()) {
    incidents.push(gr);
  }

  return incidents;
}

 

To use this script include function in a related list, you would follow the same steps as above, but you would enter the name of this script include function in the Script Include field.

By using script include functions in related lists, you can display and filter the data that is displayed in the related list. This can help you to provide users with the information that they need to do their jobs effectively.

 

Kindly, please mark my solution as Helpful/Correct, if applicable. If I could help you with your Query then, please hit the Thumb Icon and mark as Correct!!

 

Thanks & Regards, 

Revanth. K

Product Test Automation Engineer

Hi ,

We are trying to fetch the incident that are "closed_atRELATIVEGT@dayofweek@ago@365" Those incidents needs to fetch into M2M change request related list tab. Could you  help this query?
Thanks,

Suresh.

@Revanth Karra : Can you please explain note section with screenshot. I am not getting those configuration  in the system. In the related list form, I don't see any field as type. Please advise.

 

Regards,

Priyanka