The CreatorCon Call for Content is officially open! Get started here.

Business Rule for creating incident tasks

Maria DeLaCruz
Tera Guru

Hello,

I need some help with a business rule I created for creating incident tasks.   So, if the condition is met, I would like an incident task to be created if there isn't one yet.   If there is an existing incident task, but the short description does not start with "Please escalate and follow-up on", an incident task should still be created.  

Below is my business rule, and the issue is, an incident task doesn't get created when there's an existing incident task already, no matter what the short description is.  


Please help.

Thanks,
Maria

find_real_file.png

1 ACCEPTED SOLUTION

acirovic1
Giga Expert

How about:



var inctask = new GlideRecord('incident_task');


inctask.addQuery('incident', current.sys_id);


inctask.addQuery('short_description', 'STARTSWITH', ''Please escalate and follow-up on');


inctask.query();


if (!inctask.hasNext()) {


        inctask.initialize();


        inctask.incident = current.sys_id;


        inctask.prop1 = val1


        inctask.prop2 = val2


        .....


        inctask.propN = valN


        inctask.insert();


}



Never call "insert" and "update" on the same record.


View solution in original post

3 REPLIES 3

Michael Fry1
Kilo Patron

What about something like this:



var inctask = new GlideRecord('incident_task');


inctask.addQuery('incident', current.sys_id);


inctask.query();


if (inctask.next()){


        inctask.addQuery('short_description', 'Please escalate and follow-up on');


        inctask.query();


                  if (inctask.next()){


                  //do nothing


                  }


                  else {


                  //create task


                  }


        }


else {


//create task


}


acirovic1
Giga Expert

How about:



var inctask = new GlideRecord('incident_task');


inctask.addQuery('incident', current.sys_id);


inctask.addQuery('short_description', 'STARTSWITH', ''Please escalate and follow-up on');


inctask.query();


if (!inctask.hasNext()) {


        inctask.initialize();


        inctask.incident = current.sys_id;


        inctask.prop1 = val1


        inctask.prop2 = val2


        .....


        inctask.propN = valN


        inctask.insert();


}



Never call "insert" and "update" on the same record.


Thanks Aleksandar.   That worked!