Change Task cannot be assigned to the same person as the previous Catalog Task.

WilteS
Tera Contributor
What do i wrong?
 
I made a business rule for a change so thats not posible the same user do both task. 
 
(function executeRule(current, previous /*null when async*/) {
var tsk = new GlideRecord('change_task');
tsk.addQuery('Parent', '==', current.Parent);
tsk.addQuery('sys_id', '!=', current.sys_id);
tsk.query();
if (tsk.next()) {
    if (tsk.assigned_to == current.assigned_to) {
        gs.addErrorMessage('Change Task cannot be assigned to the same person as the previous Catalog Task.');
        current.setAbortAction(true);
    }
  
}
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@WilteS 

update as this

function executeRule(current, previous /*null when async*/) {
    var tsk = new GlideRecord('change_task');
    tsk.addQuery('parent', current.parent);
    tsk.addQuery('sys_id', '!=', current.sys_id);
    tsk.query();
    while (tsk.next()) {
        if (tsk.assigned_to == current.assigned_to) {
            gs.addErrorMessage('Change Task cannot be assigned to the same person as the previous Catalog Task.');
            current.setAbortAction(true);
            break;
        }
    }
}

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

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

Hi Ankur,

the value of current.parent is empty in this code rule but in the table is the value available.

 

tsk.addQuery('parent', '==', current.parent);

 

 

Anand Kumar P
Giga Patron
Giga Patron

Hi @WilteS ,

 

 

(function executeRule(current, previous /*null when async*/) {
var tsk = new GlideRecord('change_task');
tsk.addQuery('parent', '==', current.parent);
tsk.addQuery('sys_id', '!=', current.sys_id);
tsk.query();
while(tsk.next()) {
    if (tsk.assigned_to == current.assigned_to) {
        gs.addErrorMessage('Change Task cannot be assigned to the same person as the previous Catalog Task.');
        current.setAbortAction(true);
    }
  
}

 

 

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

the value of current.parent is empty in this code rule but in the table is the value available.

 

tsk.addQuery('parent', '==', current.parent);