- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:14 PM
Hi community members,
I'm working on a record producer where I need to get value of "Attachment" in my record producer script.
I need this because I'm aboring action of record producer and inserting that record somewhere else. When I'm inserting that record I need the attachment which is added by the user in Record producer to be attached in that record.
Any ideas or suggestions are helpful.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:40 PM
Hi @Utpal Dutta,
step1: Open your record producer
specify record producer if you are working on (eg.issue management- Record Producer)
step2. add the script to the Record producer
Here is the script to copy attachments in Record Producer
var newRec = new GlideRecord 'incident);//or any other table
newRec.short-description = 'created from Record producer';
newRec.description ='This record was created through a producer';
newRec.insert();
//Now copy attachments from the record producer to the new record
var sa - new GlideSysAttachment();
sa.copy('sc_item_produced_record',current.sys_id,newRec.getTableName(), newRec.sys_id);
//adjust source table name in teh .copy() line if needed
use 'sc_item_produced_record' if the attachement is saved there
step3: save the Record Producer
Testing:
1.Service catalog-> record producer and fill the form and attach a file -> submit
2. go to the target table (eg.incident in this example )
3. open a new record and check if the attachment is present.
Please mark as Correct Answer/Helpful, if applicable.
ServiceNow Developer
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:23 PM
Hello @Utpal Dutta,
In which record you want to add that attachment? Selected record producer table or somewhere else?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:25 PM
what do you want to do with that attachment?
what's your business requirement?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:26 PM
Hi @Utpal Dutta ,
when you add an attachment to the record producer it will add it to sys_attachment table with table name as the record producer tableName and sysid = sysid of the task which is not yet generated ( this sysid will be allocated to to the record once you submit the record)
it's not recommend to use the setAbortaction method inside record producer script and might not work as intended as per docs
so better create a before insert BR on the table
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:28 PM
Hello @Utpal Dutta ,
In addition to @Chaitanya ILCR point, you can copy the attachment from one table to another table using Glidesysattachment method.
// For example
var attachment = new GlideSysAttachment();
var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
var incGR = new GlideRecord('incident');
incGR.get(incidentSysID);
var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
gs.info('Copied attachments: ' + copiedAttachments);
Thank you.