Omit new button for problem task related list on problem

Alekhya12
Tera Contributor

Hi,

 

Once the problem record is assigned to a problem coordinator, no other users should have access to create a PTASK from problem task related list except Problem Manager.

from problem task list control in omit new condition tab there is a ootb code already am trying to put my conditions as below but its not working

if (new ProblemTaskStateUtilsSNC().canCreateProblemTask(parent))
    answer = false;
else if(current.assigned_to !== null && !gs.hasRole('problem_manager'))
answer = true;

 

6 REPLIES 6

Himani_14
Mega Sage
Mega Sage

Hi @Alekhya12 ,

 

Please try to use below code :-

 

var problem_coor = false;
var g = new GlideRecord('sys_user_has_role');
g.addQuery('user', parent.assigned_to);
g.addQuery('role', 'use sysID of problem Coordinator role here');
g.addQuery('active', true);
g.query();
if (g.next()) {
    problem_coor = true;
}
answer = false;
if (gs.hasRole('problem_manager') && problem_coor == true)
    answer = false;
else
    answer = true;
 
Thanks
Himani

Brad Bowman
Kilo Patron
Kilo Patron

Answer = false means do not omit/hide the button, so you'll want to reverse your logic, use parent.assigned_to instead of current, and drop the extra =:

if (parent.assigned_to != null && !gs.hasRole('problem_manager'))
    answer = true;
else if (new ProblemTaskStateUtilsSNC().canCreateProblemTask(parent))
    answer = false;

If it still isn't working, try parent.assigned_to != '' instead of null

Hi, Thanks for your response its working as we need but it impacted ootb code. In closed state new button shouldn't come but it is always executing if and showing new button to else if it's not going. please help me on this.

This will hide the button in the closed state, even for someone with the problem_manager role, and there is the original catch-all to hide the button if neither condition is satisfied.

if ((parent.assigned_to != null && !gs.hasRole('problem_manager')) || parent.state == 107)
    answer = true;
else if (new ProblemTaskStateUtilsSNC().canCreateProblemTask(parent))
    answer = false;
else
    answer = true;