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

@Star123 

what does this mean -> global.N.isMemberOf?

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

@Star123 

are you using the correct table name, field name in that?

var grTask = new GlideAggregate("Child table");
grTask.addQuery("request_number", parent.sys_id);

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

Hello @Star123 ,

 

Use

"gs.getUser().isMemberOf(parent.assignment_group)"

instead of

"global.N.isMemberOf(parent.assignment_group)"

 

And please mark your question as answered, as it was about checking the number of child tasks, not checking additional conditions.

 

Regards,

Robert

@Star123 

try this

1) you are using wrong method for group membership

2) also optimized the code a bit

var answer;

var inactiveStates = ["7", "3", "24", "20"];
if (gs.getUser().isMemberOf(parent.assignment_group) && !inactiveStates.includes(parent.state) && !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');
    return taskCount < lmt;
}

answer;

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

@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.