More than 5 child task should not be allowed to create in related list.

Star123
Tera Contributor

Hi Everyone.

 

I have a requirement. we have 1 parent table and 1 child table. in Parent table we have related, from where we are allowing to create child records.

Requirement is New button should get disable or Hide after 7 child records got created for Parent Record. 

How we can Achieve this through List UI Control.

 

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Star123 

simply add this in the Omit New condition Script field

Give count as 5 or 7 as per your requirement in script. I took 7 for example

If "Omit New condition" field is not on form then Configure Form Layout -> Then add this on form -> Then add script

AnkurBawiskar_0-1745574960805.png

var parentSysId = parent.sys_id;
var gr = new GlideRecord("childTable"); // your child table name here
gr.addQuery("parentField", parentSysId); // your parent field name here
gr.query();
if (gr.getRowCount() <= 7)
    answer = false; // don't omit
else
    answer = true; // omit the button

AnkurBawiskar_1-1745575085367.png

 

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

@Star123 

Hope you are doing good.

Did my reply answer your question?

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

Robert H
Mega Sage

Hello @Star123 ,

 

You can use this "Omit new condition" script. It uses GlideAggregate, which is the faster and recommended way than the old getRowCount() method.

 

var gaInc = new GlideAggregate('incident');
gaInc.addQuery('parent_incident', parent.getUniqueValue());
gaInc.addAggregate('COUNT');
gaInc.query();
var answer = gaInc.next() ? gaInc.getAggregate('COUNT') >= 7 : false;
answer;

 

Regards,

Robert

Star123
Tera Contributor
var answer;
if (global.N.isMemberOf(parent.assignment_group) && (!(parent.state == "7"|| parent.state == "3" || parent.state == "24" || parent.state == "20")) || !getAnswer()) { // only active true states and Not new state.
    answer = false;
} else {
        answer = true;
    }
   
    function getAnswer() {
        gs.info("my code working");
     var lmt = parseInt(gs.getProperty('x_amspi_cpmo_res_0.max_task'));
     var grTask = new GlideAggregate("Child table");
     grTask.addQuery("request_number", parent.sys_id);
     grTask.addAggregate('COUNT');
     grTask.query();
     var taskCount = grTask.getAggregate('COUNT');
     if (taskCount >= lmt) {
         return false;
     } else {
         return true;
     }
    }

answer;
 
@Ankur Bawiskar  I have written this code on list control above state part is working fine but lower function is not working. please tell me where I am doing wrong