- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2016 08:55 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2016 11:52 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2016 10:26 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2016 11:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2016 12:47 PM
Thanks Aleksandar. That worked!