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

Ankur Bawiskar
Tera Patron
Tera Patron

@Alekhya12 

please try to ensure you update the code so that it doesn't disturb OOB condition

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

Deepak Shaerma
Kilo Sage

Hi @Alekhya12 

Here’s a refactored version that should typically work:


// Get a reference to the current problem record
var probRecord = new GlideRecord(‘problem’);
probRecord.get(current.sys_id);

// Check if the current user is a problem manager
var userIsProblemManager = gs.hasRole(‘problem_manager’);

// Check if the problem is assigned to a coordinator (assuming ‘assigned_to’ field is populated)
var problemAssignedToCoordinator = probRecord.assigned_to != null && probRecord.assigned_to != ‘’;

// The New button should be hidden if the user is not a problem manager AND the problem is already assigned to a coordinator
answer = !(userIsProblemManager || !problemAssignedToCoordinator);

Please Mark this as Helpful/ Correct if this solves your query