Attachment not being transferred from record producer to HR ticket

samirmeroua
Tera Contributor

Hello All, 

 

I have created a record producer and added the variable " Attachment" (gave it a different name),

When users upload the attachment, it is being copied to the HR case being created, any advise?

 

5 REPLIES 5

vaishali231
Tera Guru

hey @samirmeroua 

Option 1: Prevent attachment usage in Record Producer

 Script

(function executeProducer(producer, current) {
    current.short_description = producer.short_description;
    current.description = producer.description;
    current.opened_for = gs.getUserID();
    if (producer.please_attach_the_l_and_l_roster) {
        delete producer.please_attach_the_l_and_l_roster;
    }
    if (!producer.short_description) {
        gs.addErrorMessage('Short description is mandatory');
        current.setAbortAction(true);
        return;
    }
    gs.info('HR Case being created for user: ' + gs.getUserName());
})(producer, current);

 

 Option 2: Delete attachments after HR Case creation (Recommended)

Allow users to upload, but remove attachments once the HR Case is created.

 Business Rule Configuration

Table: sn_hr_core_case  After insert

 Script

(function executeRule(current, previous /*null when async*/) {
   var att = new GlideRecord('sys_attachment');
   att.addQuery('table_name', 'sn_hr_core_case');
   att.addQuery('table_sys_id', current.sys_id);
   att.query();
   while (att.next()) {
       att.deleteRecord();
   }
})();

 Option 3: Conditional control (Delete only in specific cases)

If attachments should be allowed only in certain scenarios:

Script (with condition)

(function executeRule(current, previous /*null when async*/) {

   if (current.u_allow_attachment == false) {
       var att = new GlideRecord('sys_attachment');
       att.addQuery('table_name', 'sn_hr_core_case');
       att.addQuery('table_sys_id', current.sys_id);
       att.query();
       while (att.next()) {
           att.deleteRecord();
       }
   }
})();

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

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