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

Trying to create a related list which shows the active projects for the customer of the current project being displayed.

prudhvig
Tera Expert

Hi,

I am working with the Project form in Servicenow. In my project form, I have a field named "Customer Name" which is referenced to the Company Table. The Company name in that field might have multiple projects. So, now, when a name is entered in that field, all the projects which are tied to that company should be listed as a related list on the project form.

Below is the snapshot of my Project form:

Screenshot (171)_LI.jpg

And, in the Companies list of my instance, I went and added an OOB related list "Projects" to the form. So, all the projects relating to that customer would be shown in that. The project in the above snapshot is shown in that Company's Projects Related List. Below is the snapshot:

Screenshot (172)_LI.jpg

So, I want the same related list to be shown on my Project form too. Unfortunately, there is no OOB related list Projects on the Project form. I know that I have to create a relationship to achieve this, but how can I create in this scenario as I have to pull information from related list on Company form? How can I get this?

Please let me know. Thanks in advance.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Prudhvi,



Here are the steps.


1.Navigate to relationship module and create new


Name : Projects by same company


Applies to table " project(pm_project)


Queries from table : project(pm_project)


Script is


(function refineQuery(current, parent) {




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


  current.addQuery('u_customer_name', parent.u_customer_name);




})(current, parent);









Now step 2 go to the project table and add the relationship-->Right click on header->Configure->related list and search for the name   Projects by same company and add on the form.



The relationship will be visible only when you save the record.



I hope this helps.



P.S: please make sure field column name is correct i.e u_customer_name


View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Prudhvi,



Yes, you can do this. Take a look at System Definition> Relationships. There's an existing OOB entry for Incidents by Same Caller that might help as an example.



http://wiki.servicenow.com/index.php?title=Creating_Defined_Related_Lists


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Prudhvi,



Here are the steps.


1.Navigate to relationship module and create new


Name : Projects by same company


Applies to table " project(pm_project)


Queries from table : project(pm_project)


Script is


(function refineQuery(current, parent) {




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


  current.addQuery('u_customer_name', parent.u_customer_name);




})(current, parent);









Now step 2 go to the project table and add the relationship-->Right click on header->Configure->related list and search for the name   Projects by same company and add on the form.



The relationship will be visible only when you save the record.



I hope this helps.



P.S: please make sure field column name is correct i.e u_customer_name


Hi Pradeep, This has worked for me. Thank you. In addition to it, I only want to show the active projects of that customer. (i.e The Projects in Closed Complete and Cancelled state should not be shown). Can we do that?


Here you go. Update the field column name and choice values accordingly.


(function refineQuery(current, parent) {




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


  current.addQuery('company', parent.company);


  current.addQuery('state', '!=', 1); //Replace 1 with the exact choice value of Closed Complete


  current.addQuery('state', '!=', 2); //Replace 1 with the exact choice value of Cancelled state




})(current, parent);