If attachment XLS, change the Priority

AngelP83
Giga Guru

Hello Everyone,

I have an Inbound Script that creates a ticket when an email is sent to a specific email address.

Now, I would like to add a functionality: if the email contains an attachment and the attachment is a MP3, the priority must change.

I wondered if it would be better to set it up in the Inbound Script or a separate Business Rule:

This is a Business Rule I found and tried to modified, but it is not working

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the current record is an Incident record and has attachments
    if (current.getTableName() === 'incident' && current.attachment_guid) {
        // Retrieve attachment details
        var attachments = new GlideSysAttachment().get(current.attachment_guid);
        
        // Loop through attachments
        for (var i = 0; i < attachments.size(); i++) {
            // Check if the attachment has an MP3 extension
            if (attachments.get(i).file_name.endsWith('.mp3')) {
                // Set the contact_method field to "phone"
                current.contact_method = 'phone';
                
                // Additional logic or actions can be added here if needed
                
                // Break out of the loop since we found an MP3 attachment
                break;
            }
        }
    }
})(current, previous);

 

Any assistance would be appreciated.

Thank you

 

1 ACCEPTED SOLUTION

AngelP83
Giga Guru

So, I used the following script, and it WORKED!!!

but I cannot get it working when I had 2 extensions Mp3 and Wav, it only works with Wav

Any suggestions?

(function executeRule(current, previous /*null when async*/) {
    // Check if the record has attachments with the extension MP3
    var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_sys_id', current.sys_id);
    attachmentGR.addQuery('file_name', 'LIKE', '%.wav');
    attachmentGR.query();
    
    if (attachmentGR.next()) {
        // If attachments with MP3 extension found, change contact_method to EMAIL
        current.contact_method = 'Phone';
    }
})(current, previous);

View solution in original post

3 REPLIES 3

Harish KM
Kilo Patron
Kilo Patron

Hi @AngelP83 I think there is an error in the below line

if (attachments.get(i).file_name.endsWith('.mp3')) {
to
if (attachments[i].file_name.endsWith('.mp3')) {

Regards
Harish

DanielCordick
Mega Patron
Mega Patron

you might be able to use a flow for this

__DC_0-1705643343697.png

 

AngelP83
Giga Guru

So, I used the following script, and it WORKED!!!

but I cannot get it working when I had 2 extensions Mp3 and Wav, it only works with Wav

Any suggestions?

(function executeRule(current, previous /*null when async*/) {
    // Check if the record has attachments with the extension MP3
    var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_sys_id', current.sys_id);
    attachmentGR.addQuery('file_name', 'LIKE', '%.wav');
    attachmentGR.query();
    
    if (attachmentGR.next()) {
        // If attachments with MP3 extension found, change contact_method to EMAIL
        current.contact_method = 'Phone';
    }
})(current, previous);