Need add attachments when record producer is submitted

sunilsargam
Kilo Sage

Hello All,

 

I have a record producer created on the dmn_demand table. When user submits the record in ESC portal, on demand record, i need to attach one excel file. This should happen to each demand requet.

 

Is this feasible in servicenow, if yes then please let me know how to do it?

 

Thank you

 

1 REPLY 1

maliksneha9
Mega Sage

You can attach an Excel file to each Demand record created via the record producer using a few different approaches depending on your requirement.

 

 

Option 1: Attach a Static Excel File

If the same Excel file needs to be attached to every Demand:

  1. Upload the Excel file once (for example, on any record or store its sys_id)
  2. Use a Business Rule (After Insert) on dmn_demand
  3. Copy the attachment using GlideSysAttachment

Sample Script:

(function executeRule(current, previous) {
       var sourceSysId = 'PUT_SOURCE_RECORD_SYS_ID_HERE'; // record where file exists
       var gsa = new GlideSysAttachment();
       gsa.copy('dmn_demand', sourceSysId, 'dmn_demand', current.sys_id);
})(current, previous);
 

Option 2: If User Upload is Needed

If the requirement is for users to upload:

  • Add an Attachment variable in Record Producer
  • It will automatically attach to the Demand record