Deluge script to detect the array size of number/s in description, check the starting integer and perform an action

Deluge script to detect the array size of number/s in description, check the starting integer and perform an action

- > The below script would detect if the description contains a 16 digit number or more than one 16 digit number and check if that 16 digit number starts with 1,3,4,6 etc.,  It can be modified as per requirement. 

- > Based on the above check, a notification would be triggered to the assigned technician that the description has 16 digit numbers starting with a given integer.  

Steps to execute:

1. Create a Business rule as attached. 

2. Under Actions, choose custom function and save the script. So whenever a request is created, the Business rule checks the above criteria and sends the notification. 

3. Screenshots of the request where the rule was applied is attached. 


Script:

toAddress = requestObj.get("technician").get("email_id");
fromAddress = "MentionTheFromAddress";

descWordList = ["CARD", "PAN", "TARJETA", "CLIENTE"];

description = requestObj.get("description");
if(description != ""){
    description = description.replaceAll("<(.|\n)*?>" , "").replaceAll("&nbsp;" , "").replaceAll("&amp;" , "");
}
subArray = requestObj.get("subject").toList(" ");
description_array = description.toList(" ");
description_array.addAll(subArray);

returnObj = Map();
criteria1 = False;
criteria2 = False;

for each word in description_array {
    if( word.isNumber() && word.length()==16 && (word.toString().startsWithIgnoreCase("1") || word.toString().startsWithIgnoreCase("2") || word.toString().startsWithIgnoreCase("4") || word.toString().startsWithIgnoreCase("5") || word.toString().startsWithIgnoreCase("6") || word.toString().startsWithIgnoreCase("0")) ){
        criteria1 = True;
        break;
    }
}

for each word in descWordList{
    if(description_array.contains(word)){
        criteria2 = True;
        break;
    }
}

if( criteria1 ){
    mail_description = "The request subject or description has a 16 digit number";
    if( criteria2 ){
        mail_description = "The request subject or description contains keywords 'CARD', 'PAN', 'TARJETA', 'CLIENTE' and a 16 digit number";
    }
//info mail_description;
    sendmail
        [
            from: fromAddress
            to: toAddress
            subject: "Notification Mail"
            message: mail_description
        ]
    returnObj.insert("result":"success", "message":"Request Mail sent successfully");
}
else{
    returnObj.insert("result":"success", "message":"Criteria does not match!");
}
return returnObj;

                  New to ADSelfService Plus?