Business rule to not trigger if keywords are in comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 04:41 AM
Hi,
We have a business rule on an extended task table which triggers when in x states and the comments are updated by a customer end user, which then sets the status back to Active. This works fine and is used to ensure that an update from a customer via the portal doesn't get missed if it's in Awaiting Customer, etc.
=============
(function executeRule(current, previous /*null when async*/ ) {
// Set the status to Active if the status is currently set to Awaiting customer or resolved and a customer replies
var userCompany = gs.getUser().getCompanyID(); //get the company sys_id of the user making the update
if (userCompany != "4aab276269e1e0005519c01bc50243a0") { //if the user is not from internal...
current.state = 200; //...then set the status to Active
current.update();
}
})(current, previous);
==============================
I'd like to get the business rule to NOT fire if the comments includes a certain keyword/phrase... e.g., 'has requested the case be closed with the comment'. I have tried the following (and various versions of it), which will set the case to 'Resolved' if the keyphrase is used, but isn't working.... ultimately I just need the above business rule to NOT fire if the keyphrase is used.
======================
(function executeRule(current, previous /*null when async*/ ) {
// Set the status to Active if the status is currently set to Awaiting customer or resolved and a customer replies
var userCompany = gs.getUser().getCompanyID(); //get the company sys_id of the user making the update
var comment = current.comments.getJournalEntry(1);
if (userCompany != "4aab276269e1e0005519c01bc50243a0") { //if the user is not from internal...
current.state = 200; //...then set the status to Active
current.update();
} else if (userCompany != "4aab276269e1e0005519c01bc50243a0" && comment.indexOf("has requested the case be closed with the comment")) {//if the user is not from internal but includes the closure comments...
current.state = 600; //...then set the status to Resolved
current.update();
}
})(current, previous);
=======================
Are there any suggestions on how to use the original script above to not trigger if the new comments include the key phrase? I've used 'comments.toLowerCase.indexOf' several times before in a positive manner (i.e., if statement when phrase is included) but not sure how to use the command on the negative, i.e., to only fire when there is no key phrase included.
Any help would be greatly appreciated, many thanks in advance,
Gabe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 05:28 AM
Hi ,
If it is related to comments , try querying the sys_journal_field and get the comments for your particular ticket and then use indexof and if it returns the value you can use setAbortAction accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 08:24 AM
Hi @Anubhav24
Thanks for the input... wouldn't setAbortAction actually cause the action to stop/fail? Unfortunately that's not what would be needed on this... I just don't want the initial BR to trigger if the comments are included in the comments field. So I assume I need that 1st if statement to have a condition that says the variable comments 'does not include "has requested the case be closed with the comment"?
I set up a query the journal table as per the below... how do I set the if statement to include a condition that says 'do not fire if the journal entry from the 'comments' variable does not include "has requested the case be closed with the comment"?
=========================
(function executeRule(current, previous /*null when async*/ ) {
//Set the status to Active if the status is currently set to Awaiting customer or resolved and a customer replies
var userCompany = gs.getUser().getCompanyID(); //get the company sys_id of the user making the update
var comments = new GlideRecord('sys_journal_field');
comments.addQuery('element', 'comments');
comments.addQuery('element_id', current.sysid);
comments.query();
if (userCompany != "4aab276269e1e0005519c01bc50243a0") { //if the user is not from internal...
current.state = 200; //...then set the status to Active
current.update();
}
})(current, previous);
========================
I just need that if statement to not trigger if that key phrase is included in the comment made by the end user. Does that make sense?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 11:58 PM
'do not fire if the journal entry from the 'comments' variable does not include "has requested the case be closed with the comment" : can you try below
if (comments contains 'has requested the case---')
{
<do something>
}
just write the positive case