Create a related list on the Portfolio table

BiancaK
Tera Expert

Good Day Community

 

I am currently trying to create a related list on the Portfolio table. 

 

This is my requirement: 

- On the Project form there is currently a related list named "Actions". 

- When a user creates an Action on the project form and the project is associated to a Portfolio then the actions on the project record should roll up to the Portfolio record. 

 

This is what I have attempted thus far:

 

This is the related lists on the Portfolio record. I have created the Related List named Project Actions. Currently all actions are displaying. I only want actions associated to the specific Portfolio to display

BiancaK_0-1740574008696.png

Is there a way to achieve this?

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@BiancaK 

I hope this will work for you as it worked for me

Please enhance as per your requirement

(function refineQuery(current, parent) {

    // Add your code here, such as current.addQuery(field, value);
    var projectArr = [];
    var gr = new GlideRecord("pm_m2m_portfolio_project");
    gr.addQuery("portfolio", parent.sys_id);
    gr.query();
    while (gr.next()) {
        projectArr.push(gr.project.pm_project.toString());
    }

    current.addQuery('parent', 'IN', projectArr.toString());

})(current, parent);

AnkurBawiskar_0-1740575617854.png

 

project portfolio related list.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@BiancaK 

seems you have created a defined/custom relationship between your Portfolio and the Actions table

you can use script in that and bring the actions for that Portfolio

1) Your current form is Portfolio so go to pm_m2m_portfolio_project table and get the Projects associated to this Portfolio

2) then once you get the projects query the project_action table with the above projects and push the sysId of Project Action

3) then form the query

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Rohit  Singh
Mega Sage

Hi @BiancaK ,

 

I believe you have already created a relationship in the Relationship Table. Now utilize the script section to establish a relationship between the Project Action and Portfolio Record.

 

Refer below example:

RohitSingh3_1-1740575349967.png

 

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

 

Regards,
Rohit

Ankur Bawiskar
Tera Patron
Tera Patron

@BiancaK 

I hope this will work for you as it worked for me

Please enhance as per your requirement

(function refineQuery(current, parent) {

    // Add your code here, such as current.addQuery(field, value);
    var projectArr = [];
    var gr = new GlideRecord("pm_m2m_portfolio_project");
    gr.addQuery("portfolio", parent.sys_id);
    gr.query();
    while (gr.next()) {
        projectArr.push(gr.project.pm_project.toString());
    }

    current.addQuery('parent', 'IN', projectArr.toString());

})(current, parent);

AnkurBawiskar_0-1740575617854.png

 

project portfolio related list.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thanks @Ankur Bawiskar let me try this solution.