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?

                    • Related Articles

                    • How to implement dynamic request approval using FAFR and custom triggers - Deluge

                      This is a sample script written in Deluge to handle Conditional Approvals for Incident \ Service Requests, through Custom Triggers using Field and Form Rules.  One of the advantages of using this script that no modification in the script is required ...
                    • Deluge Script to show request attributes in Task Subject / Description from builds: 10600 and 14306

                      Requirement: To show the request field values such as Request Type, Status etc., or the additional field values in the Task subject/description. Use case: When a task is triggered from a request, it should contain the request details (configured) in ...
                    • Update a request based on certain values - Deluge

                      This post describes the use of a deluge script to update requests based on values given a global function, namely "request_properties".  This action can be performed using Custom Triggers. Refer to this link for Python ...
                    • Update Requester from Request Description

                      Use case: When a request is submitted on behalf of a user via email, the request description contains the requester's full name. Script to update the ticket requester accordingly. Tested on builds: 14306,14500. Steps to follow: Go to Admin > Request ...
                    • How to debug a python/deluge script

                      Common Debugging steps: 1. Confirm if all the API used are in proper format: In latest v3 APIs, "format": "json" is removed from parameters Notes addition API is modified from: "request_notes" to "notes" in recent builds 2. Check if the udf_fields ...