Display error message when user create a more than one planning task

Manasa Allu
Tera Contributor

Hi Team,

 

Display error message, when user create more than one planning task on the change request.

 

Regards,

Manasa 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Manasa Allu 

you can use before insert BR on change_task and check if for this CHG there already exists a planning task.

if yes then show error message and abort the business rule

what script did you start with and where are you stuck?

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

Hi Ankur,

 

Please provide the step-by-step process for the above requirement.

 

Regards,

Manasa.

@Manasa Allu 

I would suggest to start the script from your side as it will be learning for you as well.

if you are stuck community members can help you.

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

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @Manasa Allu ,

                                   Assuming you have some Planning Task table associated with change request. If its Change task just change table name in script. 

Write Before BR on Planning Task/ Change Task  as below

// Query the Planning Task table to count existing planning tasks related to this Change Request
        var planningTaskCount = new GlideAggregate('planning_task'); // if its change task replace name accordingly
        planningTaskCount.addQuery('change_request', current.sys_id); // there should be filed on table poninting to CR
        planningTaskCount.addAggregate('COUNT');
        planningTaskCount.query();
        
        var numberOfPlanningTasks = 0;
        if (planningTaskCount.next()) {
            numberOfPlanningTasks = parseInt(planningTaskCount.getAggregate('COUNT'));
        }
        
        // Check if there's already more than one planning task related to the change request
        if (numberOfPlanningTasks > 1) {
            // Display an error message and prevent the creation of the new planning task
            gs.addErrorMessage('Only one planning task is allowed per Change Request.');
            current.setAbortAction(true);
        }

If you are not aware about before business rule check it What is Before Business Rule in ServiceNow 

 

Kindly mark correct and helpful if applicable