How to restrict assigning 2 sctasks

nameisnani
Mega Sage

Hi Team 

 

 

How to restrict assigning 2 sctasks to a same member when the tasks are generated from same ritm . 

 

I have wirtten this BR on ritm table , 

 

nameisnani_0-1701167274354.png

 

nameisnani_1-1701167274308.png

 

 

 

Here we are triggering sequential task . I am going to assign same person to 2nd task it should through an error .Which is not working ,

 

nameisnani_2-1701167274365.png

 

Note - it should throw an error and abort action

 

@Jaspal Singh @Sonam_Tiwari 

 

Please help me here , please provide solution 

 

Thanks in advance 

 

1 ACCEPTED SOLUTION

Anand Kumar P
Giga Patron
Giga Patron

Hi @nameisnani ,

You should create before insert and update business rule on sc_task table i have tried in my pdi its working.

AnandKumarP_1-1701169443383.png

 

(function executeRule(current, previous /*null when async*/) {

	var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.request_item)) {
        var existingTasks = new GlideRecord('sc_task');
        existingTasks.addQuery('assigned_to', current.assigned_to);
        existingTasks.addQuery('request_item', current.request_item);
        existingTasks.addQuery('sys_id', '!=', current.sys_id);
        existingTasks.query();
        if (existingTasks.hasNext()) {
            gs.addErrorMessage('Another task is already assigned to the same member for this RITM. Please review the assignments.');
            current.setAbortAction(true);
        }
    }
current.setAbortAction(false);


})(current, previous);

AnandKumarP_0-1701169409688.png

AnandKumarP_2-1701169472161.png

 

Mark it as solution proposed and helpful if it serves your purpose.

Thanks,

Anand

 

View solution in original post

3 REPLIES 3

Harsh_Deep
Giga Sage
Giga Sage

Hello @nameisnani 

 

As I can see you have written BR on RITM table but you should have to write this BR on the SC Task Table then only this will work.

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Hi @Harsh_Deep 

 

Yes I have tried with sctask also same behaviour.

Anand Kumar P
Giga Patron
Giga Patron

Hi @nameisnani ,

You should create before insert and update business rule on sc_task table i have tried in my pdi its working.

AnandKumarP_1-1701169443383.png

 

(function executeRule(current, previous /*null when async*/) {

	var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.request_item)) {
        var existingTasks = new GlideRecord('sc_task');
        existingTasks.addQuery('assigned_to', current.assigned_to);
        existingTasks.addQuery('request_item', current.request_item);
        existingTasks.addQuery('sys_id', '!=', current.sys_id);
        existingTasks.query();
        if (existingTasks.hasNext()) {
            gs.addErrorMessage('Another task is already assigned to the same member for this RITM. Please review the assignments.');
            current.setAbortAction(true);
        }
    }
current.setAbortAction(false);


})(current, previous);

AnandKumarP_0-1701169409688.png

AnandKumarP_2-1701169472161.png

 

Mark it as solution proposed and helpful if it serves your purpose.

Thanks,

Anand