We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Attachment Added Event Working in Backend but Not Triggering from Service Portal

JyotiranjanC566
Giga Contributor

Hi All,

I created an Event + Business Rule on sys_attachment (After, Insert) to trigger an email notification when an attachment is added to sc_req_item (RITM).

It works correctly when attachment is added from the backend form view.

However, when attachment is added through Service Portal, the event is not firing and notification is not triggered.

Attachment record is getting created in sys_attachment with correct table_name and table_sys_id.

Business Rule details:

  • Table: sys_attachment

  • When: After

  • Insert: ✔

  • Advanced: ✔
    this is the script

    (function executeRule(current, previous) {

        if (!current.table_sys_id)
            return;

        // RITM
        if (current.table_name == 'sc_req_item') {

            var ritm = new GlideRecord('sc_req_item');
            if (ritm.get(current.table_sys_id)) {

                gs.eventQueue(
                    'attachment.added',
                    ritm,
                    ritm.sys_id,
                    current.file_name
                );

                gs.log('RITM Attachment Event Fired: ' + ritm.number);
            }
        }

        // Incident
        if (current.table_name == 'incident') {

            var inc = new GlideRecord('incident');
            if (inc.get(current.table_sys_id)) {

                gs.eventQueue(
                    'attachment.added.incident',
                    inc,
                    inc.sys_id,
                    current.file_name
                );

                gs.log('Incident Attachment Event Fired: ' + inc.number);
            }
        }

    })(current, previous);

     

2 REPLIES 2

Tanushree Maiti
Giga Sage

Hi @JyotiranjanC566 ,

 

Could you please try with Async instead of after business rule and check.

 

Also , you can check following KB Article "After Insert Business rule on sys_attachment table does not execute when records are created through..."

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB2208821

 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

vaishali231
Tera Guru

hey @JyotiranjanC566 


Instead of loading the target record again using GlideRecord and passing sys_id as event parameters.

Business Rule 

(function executeRule(current, previous) {

if (!current.table_sys_id)
return;

if (current.table_name == 'sc_req_item') {

var ritm = new GlideRecordSecure('sc_req_item');
if (ritm.get(current.table_sys_id)) {

gs.eventQueue(
'attachment.added',
ritm,
current.file_name,
''
);

gs.log('RITM Attachment Event Fired: ' + ritm.number);
}
}
else if (current.table_name == 'incident') {

var inc = new GlideRecordSecure('incident');
if (inc.get(current.table_sys_id)) {

gs.eventQueue(
'attachment.added.incident',
inc,
current.file_name,
''
);

gs.log('Incident Attachment Event Fired: ' + inc.number);
}
}

})(current, previous);

***********************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

 

Regards

Vaishali Singh